Skip to content

Commit 688ff24

Browse files
committed
[tests] Updated unit and integration tests for glossary category and term
1 parent 76d860d commit 688ff24

File tree

4 files changed

+74
-20
lines changed

4 files changed

+74
-20
lines changed

tests/integration/glossary_test.py

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,50 @@ def create_glossary(client: AtlanClient, name: str) -> AtlasGlossary:
3737
def create_category(
3838
client: AtlanClient,
3939
name: str,
40-
glossary: AtlasGlossary,
40+
glossary: Optional[AtlasGlossary] = None,
41+
glossary_guid: Optional[str] = None,
42+
glossary_qualified_name: Optional[str] = None,
4143
parent: Optional[AtlasGlossaryCategory] = None,
4244
) -> AtlasGlossaryCategory:
43-
c = AtlasGlossaryCategory.create(
44-
name=name, anchor=glossary, parent_category=parent or None
45-
)
45+
if glossary:
46+
c = AtlasGlossaryCategory.creator(
47+
name=name, anchor=glossary, parent_category=parent or None
48+
)
49+
elif glossary_guid:
50+
c = AtlasGlossaryCategory.creator(
51+
name=name, glossary_guid=glossary_guid, parent_category=parent or None
52+
)
53+
elif glossary_qualified_name:
54+
c = AtlasGlossaryCategory.creator(
55+
name=name,
56+
glossary_qualified_name=glossary_qualified_name,
57+
parent_category=parent or None,
58+
)
4659
return client.asset.save(c).assets_created(AtlasGlossaryCategory)[0]
4760

4861

4962
def create_term(
5063
client: AtlanClient,
5164
name: str,
52-
glossary_guid: str,
65+
glossary: Optional[AtlasGlossary] = None,
66+
glossary_guid: Optional[str] = None,
67+
glossary_qualified_name: Optional[str] = None,
5368
categories: Optional[List[AtlasGlossaryCategory]] = None,
5469
) -> AtlasGlossaryTerm:
55-
t = AtlasGlossaryTerm.create(
56-
name=StrictStr(name),
57-
glossary_guid=StrictStr(glossary_guid),
58-
categories=categories,
59-
)
70+
if glossary:
71+
t = AtlasGlossaryTerm.creator(name=name, anchor=glossary, categories=categories)
72+
elif glossary_guid:
73+
t = AtlasGlossaryTerm.creator(
74+
name=name,
75+
glossary_guid=glossary_guid,
76+
categories=categories,
77+
)
78+
elif glossary_qualified_name:
79+
t = AtlasGlossaryTerm.creator(
80+
name=name,
81+
glossary_qualified_name=glossary_qualified_name,
82+
categories=categories,
83+
)
6084
r = client.asset.save(t)
6185
return r.assets_created(AtlasGlossaryTerm)[0]
6286

@@ -144,8 +168,12 @@ def leaf1aa_category(
144168
hierarchy_glossary: AtlasGlossary,
145169
mid1a_category: AtlasGlossaryCategory,
146170
) -> Generator[AtlasGlossaryCategory, None, None]:
171+
assert hierarchy_glossary and hierarchy_glossary.guid
147172
c = create_category(
148-
client, TestId.make_unique("leaf1aa"), hierarchy_glossary, parent=mid1a_category
173+
client,
174+
TestId.make_unique("leaf1aa"),
175+
glossary_guid=hierarchy_glossary.guid,
176+
parent=mid1a_category,
149177
)
150178
yield c
151179
delete_asset(client, guid=c.guid, asset_type=AtlasGlossaryCategory)
@@ -158,7 +186,10 @@ def leaf1ab_category(
158186
mid1a_category: AtlasGlossaryCategory,
159187
) -> Generator[AtlasGlossaryCategory, None, None]:
160188
c = create_category(
161-
client, TestId.make_unique("leaf1ab"), hierarchy_glossary, parent=mid1a_category
189+
client,
190+
TestId.make_unique("leaf1ab"),
191+
glossary_qualified_name=hierarchy_glossary.qualified_name,
192+
parent=mid1a_category,
162193
)
163194
yield c
164195
delete_asset(client, guid=c.guid, asset_type=AtlasGlossaryCategory)
@@ -283,7 +314,7 @@ def test_category(
283314
def term1(
284315
client: AtlanClient, glossary: AtlasGlossary
285316
) -> Generator[AtlasGlossaryTerm, None, None]:
286-
t = create_term(client, name=TERM_NAME1, glossary_guid=glossary.guid)
317+
t = create_term(client, name=TERM_NAME1, glossary=glossary)
287318
yield t
288319
delete_asset(client, guid=t.guid, asset_type=AtlasGlossaryTerm)
289320

@@ -353,7 +384,9 @@ def test_term2(
353384
def term3(
354385
client: AtlanClient, glossary: AtlasGlossary
355386
) -> Generator[AtlasGlossaryTerm, None, None]:
356-
t = create_term(client, name=TERM_NAME3, glossary_guid=glossary.guid)
387+
t = create_term(
388+
client, name=TERM_NAME3, glossary_qualified_name=glossary.qualified_name
389+
)
357390
yield t
358391
delete_asset(client, guid=t.guid, asset_type=AtlasGlossaryTerm)
359392

tests/unit/model/glossary_category_test.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ def test_create(
5858
anchor=anchor,
5959
parent_category=parent_category,
6060
)
61-
6261
assert sut.name == GLOSSARY_CATEGORY_NAME
6362
assert sut.qualified_name
64-
assert sut.parent_category == parent_category
65-
assert sut.anchor == anchor
63+
64+
expected_parent = (
65+
parent_category.trim_to_reference() if sut.parent_category else parent_category
66+
)
67+
assert sut.parent_category == expected_parent
68+
69+
expected_anchor = anchor.trim_to_reference() if sut.anchor else anchor
70+
assert sut.anchor == expected_anchor
6671

6772

6873
@pytest.mark.parametrize(

tests/unit/model/glossary_term_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_create(
122122
assert sut.qualified_name
123123
assert sut.categories == categories
124124
assert (
125-
(anchor and sut.anchor == anchor)
125+
(anchor and sut.anchor == anchor.trim_to_reference())
126126
or (
127127
glossary_qualified_name
128128
and sut.anchor is not None

tests/unit/test_glossary_term.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ def test_create_atttributes_without_required_parameters_raises_value_error(
5252
@pytest.mark.parametrize(
5353
"name, anchor, glossary_qualified_name, glossary_guid",
5454
[
55-
("Glossary", AtlasGlossary(), None, None),
55+
("Glossary", AtlasGlossary.ref_by_guid(guid="123"), None, None),
56+
(
57+
"Glossary",
58+
AtlasGlossary.ref_by_qualified_name(
59+
qualified_name="glossary/qualifiedName"
60+
),
61+
None,
62+
None,
63+
),
5664
("Glossary", None, "glossary/qualifiedName", None),
5765
("Glossary", None, None, "123"),
5866
],
@@ -126,7 +134,15 @@ def test_create_without_required_parameters_raises_value_error(
126134
@pytest.mark.parametrize(
127135
"name, anchor, glossary_qualified_name, glossary_guid",
128136
[
129-
("Glossary", AtlasGlossary(), None, None),
137+
("Glossary", AtlasGlossary.ref_by_guid(guid="123"), None, None),
138+
(
139+
"Glossary",
140+
AtlasGlossary.ref_by_qualified_name(
141+
qualified_name="glossary/qualifiedName"
142+
),
143+
None,
144+
None,
145+
),
130146
("Glossary", None, "glossary/qualifiedName", None),
131147
("Glossary", None, None, "123"),
132148
],

0 commit comments

Comments
 (0)