forked from launchdarkly/python-server-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_attribute_ref.py
More file actions
54 lines (46 loc) · 1.77 KB
/
Copy pathtest_attribute_ref.py
File metadata and controls
54 lines (46 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from ldclient.impl.model.attribute_ref import *
import pytest
class TestAttributeRef:
@pytest.mark.parametrize("input", ["", "/"])
def test_invalid_attr_ref_from_path(self, input: str):
a = AttributeRef.from_path(input)
assert a.valid is False
assert a.error is not None
assert a.depth == 0
@pytest.mark.parametrize("input", [""])
def test_invalid_attr_ref_from_literal(self, input: str):
a = AttributeRef.from_literal(input)
assert a.valid is False
assert a.error is not None
assert a.depth == 0
@pytest.mark.parametrize("input", ["name", "name/with/slashes", "name~0~1with-what-looks-like-escape-sequences"])
def test_ref_with_no_leading_slash(self, input: str):
a = AttributeRef.from_path(input)
assert a.valid is True
assert a.error is None
assert a.depth == 1
assert a[0] == input
@pytest.mark.parametrize("input,unescaped", [
("/name", "name"),
("/0", "0"),
("/name~1with~1slashes~0and~0tildes", "name/with/slashes~and~tildes")
])
def test_ref_simple_with_leading_slash(self, input: str, unescaped: str):
a = AttributeRef.from_path(input)
assert a.valid is True
assert a.error is None
assert a.depth == 1
assert a[0] == unescaped
@pytest.mark.parametrize("input", [])
def test_literal(self, input: str):
a = AttributeRef.from_literal(input)
assert a.valid is True
assert a.error is None
assert a.depth == 1
assert a[0] == input
def test_get_component(self):
a = AttributeRef.from_path("/first/sec~1ond/third")
assert a.depth == 3
assert a[0] == "first"
assert a[1] == "sec/ond"
assert a[2] == "third"