Skip to content

Commit 69e0300

Browse files
committed
[tests] Added integration tests for UserDefRelationship on terms
1 parent 52f7575 commit 69e0300

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

tests/integration/glossary_test.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from pyatlan.client.atlan import AtlanClient
1313
from pyatlan.errors import InvalidRequestError, NotFoundError
1414
from pyatlan.model.assets import AtlasGlossary, AtlasGlossaryCategory, AtlasGlossaryTerm
15+
from pyatlan.model.assets.relations import UserDefRelationship
1516
from pyatlan.model.enums import SaveSemantic
1617
from pyatlan.model.fields.atlan_fields import AtlanField
1718
from pyatlan.model.fluent_search import CompoundQuery, FluentSearch
@@ -295,6 +296,15 @@ def leaf2ba_category(
295296
delete_asset(client, guid=c.guid, asset_type=AtlasGlossaryCategory)
296297

297298

299+
@pytest.fixture(scope="module")
300+
def term_user_def_relationship() -> UserDefRelationship:
301+
test_id = MODULE_NAME.lower()
302+
return UserDefRelationship(
303+
from_type_label=f"Testing from label ({test_id})",
304+
to_type_label=f"Testing to label ({test_id})",
305+
)
306+
307+
298308
def test_category(
299309
client: AtlanClient, category: AtlasGlossaryCategory, glossary: AtlasGlossary
300310
):
@@ -1061,3 +1071,88 @@ def test_move_sub_category_to_category(
10611071
assert top1_category.qualified_name in root_category_qns_updated
10621072
assert top2_category.qualified_name in root_category_qns_updated
10631073
assert mid1a_category.qualified_name in root_category_qns_updated
1074+
1075+
1076+
def test_user_def_relationship_on_terms(
1077+
client: AtlanClient,
1078+
term1: AtlasGlossaryTerm,
1079+
term2: AtlasGlossaryTerm,
1080+
glossary: AtlasGlossary,
1081+
term_user_def_relationship: UserDefRelationship,
1082+
):
1083+
term1_to_update = AtlasGlossaryTerm.updater(
1084+
qualified_name=term1.qualified_name,
1085+
name=term1.name,
1086+
glossary_guid=glossary.guid,
1087+
)
1088+
term2 = AtlasGlossaryTerm.ref_by_guid(term2.guid)
1089+
term1_to_update.user_def_relationship_to = [
1090+
term_user_def_relationship.user_def_relationship_to(term2)
1091+
]
1092+
1093+
response = client.asset.save(term1_to_update)
1094+
assert response.mutated_entities
1095+
assert response.mutated_entities.CREATE is None
1096+
assert response.mutated_entities.UPDATE
1097+
assert len(response.mutated_entities.UPDATE) == 2
1098+
assets = response.assets_updated(asset_type=AtlasGlossaryTerm)
1099+
assert len(assets) == 2
1100+
1101+
1102+
def _assert_relationship(relationship, expected_type_name, udr):
1103+
assert relationship
1104+
assert relationship.guid
1105+
assert relationship.type_name
1106+
assert relationship.attributes
1107+
assert relationship.attributes.relationship_attributes
1108+
assert relationship.attributes.relationship_attributes.attributes
1109+
assert (
1110+
relationship.attributes.relationship_attributes.type_name == expected_type_name
1111+
)
1112+
assert relationship.attributes.relationship_attributes == udr
1113+
1114+
1115+
@pytest.mark.order(after="test_user_def_relationship_on_terms")
1116+
def test_search_user_def_relationship_on_terms(
1117+
client: AtlanClient,
1118+
term1: AtlasGlossaryTerm,
1119+
term2: AtlasGlossaryTerm,
1120+
term_user_def_relationship: UserDefRelationship,
1121+
):
1122+
# Wait for assets to be indexed
1123+
sleep(5)
1124+
assert term1 and term1.guid
1125+
assert term2 and term2.guid
1126+
results = (
1127+
FluentSearch()
1128+
.select()
1129+
.where_some(AtlasGlossaryTerm.GUID.eq(term1.guid))
1130+
.where_some(AtlasGlossaryTerm.GUID.eq(term2.guid))
1131+
.include_on_results(AtlasGlossaryTerm.USER_DEF_RELATIONSHIP_TO)
1132+
.include_on_results(AtlasGlossaryTerm.USER_DEF_RELATIONSHIP_FROM)
1133+
.include_relationship_attributes(True)
1134+
.execute(client=client)
1135+
)
1136+
assert results and results.count == 2
1137+
for asset in results:
1138+
assert asset and asset.guid
1139+
if asset.guid == term1.guid:
1140+
assert (
1141+
asset.user_def_relationship_to
1142+
and len(asset.user_def_relationship_to) == 1
1143+
)
1144+
_assert_relationship(
1145+
asset.user_def_relationship_to[0],
1146+
UserDefRelationship.__name__,
1147+
term_user_def_relationship,
1148+
)
1149+
else:
1150+
assert (
1151+
asset.user_def_relationship_from
1152+
and len(asset.user_def_relationship_from) == 1
1153+
)
1154+
_assert_relationship(
1155+
asset.user_def_relationship_from[0],
1156+
UserDefRelationship.__name__,
1157+
term_user_def_relationship,
1158+
)

0 commit comments

Comments
 (0)