source: flexoentity/tests/test_from_strings.py@ 6ad031b

Last change on this file since 6ad031b was 6ad031b, checked in by Enrico Schwass <ennoausberlin@…>, 2 months ago

another round of domain refactoring

  • Property mode set to 100644
File size: 5.3 KB
Line 
1import pytest
2from flexoentity.id_factory import FlexOID
3
4
5# ─────────────────────────────────────────────────────────────────────────────
6# Valid construction via from_strings
7# ─────────────────────────────────────────────────────────────────────────────
8def test_from_strings_valid():
9 oid = FlexOID.from_strings(
10 domain_id="GEN_GENERIC",
11 entity_type="I",
12 date="251101",
13 hash_part="A1B2C3D4E5F6",
14 version="001",
15 state="D",
16 )
17
18 assert isinstance(oid, FlexOID)
19 assert str(oid) == "GEN_GENERIC-I251101-A1B2C3D4E5F6@001D"
20
21 assert oid.domain_id == "GEN_GENERIC"
22 assert oid.entity_type == "I"
23 assert oid.date_str == "251101"
24 assert oid.hash_part == "A1B2C3D4E5F6"
25 assert oid.version == 1
26 assert oid.state_code == "D"
27
28
29# ─────────────────────────────────────────────────────────────────────────────
30# from_dict should delegate to from_strings
31# ─────────────────────────────────────────────────────────────────────────────
32def test_from_dict_valid():
33 data = {
34 "domain_id": "AF",
35 "entity_type": "C",
36 "date": "250101",
37 "hash": "ABCDEF123456",
38 "version": "003",
39 "state": "A",
40 }
41
42 oid = FlexOID.from_dict(data)
43
44 assert isinstance(oid, FlexOID)
45 assert str(oid) == "AF-C250101-ABCDEF123456@003A"
46
47
48# ─────────────────────────────────────────────────────────────────────────────
49# Missing dict fields must fail loudly
50# ─────────────────────────────────────────────────────────────────────────────
51def test_from_dict_missing_fields():
52 incomplete = {
53 "domain": "AF",
54 "entity_type": "C",
55 # missing: date, hash, version, state
56 }
57
58 with pytest.raises(ValueError):
59 FlexOID.from_dict(incomplete)
60
61
62# ─────────────────────────────────────────────────────────────────────────────
63# Invalid strings should be rejected in from_strings
64# ─────────────────────────────────────────────────────────────────────────────
65@pytest.mark.parametrize("domain", ["geN", "GEN!", "GEN-", "", None])
66def test_from_strings_invalid_domain(domain):
67 with pytest.raises(ValueError):
68 FlexOID.from_strings(
69 domain_id=domain,
70 entity_type="I",
71 date="241001",
72 hash_part="AABBCCDDEEFF",
73 version="001",
74 state="D",
75 )
76
77
78@pytest.mark.parametrize("etype", ["", "ITEM", "i", "aa"])
79def test_from_strings_invalid_entity_type(etype):
80 with pytest.raises(ValueError):
81 FlexOID.from_strings(
82 domain_id="GEN",
83 entity_type=etype,
84 date="241001",
85 hash_part="AABBCCDDEEFF",
86 version="001",
87 state="D",
88 )
89
90
91@pytest.mark.parametrize("date", ["20241001", "2410", "ABCDEF", None])
92def test_from_strings_invalid_date(date):
93 with pytest.raises(ValueError):
94 FlexOID.from_strings(
95 domain_id="GEN",
96 entity_type="I",
97 date=date,
98 hash_part="AABBCCDDEEFF",
99 version="001",
100 state="D",
101 )
102
103
104@pytest.mark.parametrize("hash_part", ["abc123", "ZZZZZZZZ", "GHIJKL", "", None])
105def test_from_strings_invalid_hash(hash_part):
106 with pytest.raises(ValueError):
107 FlexOID.from_strings(
108 domain_id="GEN",
109 entity_type="I",
110 date="241001",
111 hash_part=hash_part,
112 version="001",
113 state="D",
114 )
115
116
117@pytest.mark.parametrize("version", ["1", "01", "1000", "0A1", "abc", None])
118def test_from_strings_invalid_version(version):
119 with pytest.raises(ValueError):
120 FlexOID.from_strings(
121 domain_id="GEN",
122 entity_type="I",
123 date="241001",
124 hash_part="AABBCCDDEEFF",
125 version=version,
126 state="D",
127 )
128
129
130@pytest.mark.parametrize("state", ["d", "DD", "1", "", None])
131def test_from_strings_invalid_state(state):
132 with pytest.raises(ValueError):
133 FlexOID.from_strings(
134 domain_id="GEN",
135 entity_type="I",
136 date="241001",
137 hash_part="AABBCCDDEEFF",
138 version="001",
139 state=state,
140 )
Note: See TracBrowser for help on using the repository browser.