11# SPDX-License-Identifier: Apache-2.0
22# Copyright 2022 Atlan Pte. Ltd.
33import pytest
4+ from pydantic .v1 import parse_obj_as
45
56import pyatlan .cache .atlan_tag_cache
67from pyatlan .client .atlan import AtlanClient
7- from pyatlan .model .constants import DELETED_
8+ from pyatlan .model .assets import Purpose
89from pyatlan .model .core import AtlanTagName
910
1011ATLAN_TAG_ID = "yiB7RLvdC2yeryLPjaDeHM"
@@ -32,23 +33,6 @@ def current_client(client, monkeypatch):
3233 )
3334
3435
35- def test_init_with_bad_atlan_tag_name_raises_value_error (
36- current_client : AtlanClient , monkeypatch
37- ):
38- def get_id_for_name (_ , __ ):
39- return None
40-
41- monkeypatch .setattr (
42- pyatlan .cache .atlan_tag_cache .AtlanTagCache ,
43- "get_id_for_name" ,
44- get_id_for_name ,
45- )
46- with pytest .raises (
47- ValueError , match = f"{ GOOD_ATLAN_TAG_NAME } is not a valid Classification"
48- ):
49- AtlanTagName (GOOD_ATLAN_TAG_NAME )
50-
51-
5236@pytest .fixture ()
5337def good_atlan_tag (current_client : AtlanClient , monkeypatch ):
5438 def get_id_for_name (_ , value ):
@@ -83,7 +67,7 @@ def get_id_for_name(_, value):
8367def test_convert_to_display_text_when_atlan_tag_passed_returns_same_atlan_tag (
8468 good_atlan_tag ,
8569):
86- assert good_atlan_tag is AtlanTagName ._convert_to_display_text (good_atlan_tag )
70+ assert good_atlan_tag is AtlanTagName ._convert_to_tag_name (good_atlan_tag )
8771
8872
8973def test_convert_to_display_text_when_bad_string (
@@ -98,100 +82,91 @@ def get_name_for_id(_, __):
9882 get_name_for_id ,
9983 )
10084
101- assert (
102- AtlanTagName ._convert_to_display_text ("bad" ).__repr__ ()
103- == f"AtlanTagName('{ DELETED_ } ')"
104- )
85+ assert AtlanTagName ._convert_to_tag_name ("bad" ).__repr__ () == "AtlanTagName('bad')"
86+
10587
88+ def test_convert_to_tag_name (current_client : AtlanClient , monkeypatch ):
89+ sut = AtlanTagName ._convert_to_tag_name (ATLAN_TAG_ID )
10690
107- def test_convert_to_display_text_when_id (current_client : AtlanClient , monkeypatch ):
91+ assert str (sut ) == ATLAN_TAG_ID
92+
93+
94+ def test_json_encode_atlan_tag (good_atlan_tag ):
95+ assert AtlanTagName .json_encode_atlan_tag (good_atlan_tag ) == ATLAN_TAG_ID
96+
97+
98+ def test_asset_tag_name_field_deserialization (current_client : AtlanClient , monkeypatch ):
10899 def get_name_for_id (_ , __ ):
109- return GOOD_ATLAN_TAG_NAME
100+ return None
110101
111- def get_id_for_name (_ , value ):
112- assert value == GOOD_ATLAN_TAG_NAME
113- return GOOD_ATLAN_TAG_NAME
102+ def get_id_for_name (_ , __ ):
103+ return None
114104
115105 monkeypatch .setattr (
116106 pyatlan .cache .atlan_tag_cache .AtlanTagCache ,
117107 "get_id_for_name" ,
118108 get_id_for_name ,
119109 )
110+
120111 monkeypatch .setattr (
121112 pyatlan .cache .atlan_tag_cache .AtlanTagCache ,
122113 "get_name_for_id" ,
123114 get_name_for_id ,
124115 )
125-
126- sut = AtlanTagName ._convert_to_display_text (ATLAN_TAG_ID )
127-
128- assert str (sut ) == GOOD_ATLAN_TAG_NAME
129-
130-
131- def test_json_encode_atlan_tag (good_atlan_tag ):
132- assert AtlanTagName .json_encode_atlan_tag (good_atlan_tag ) == ATLAN_TAG_ID
133-
134-
135- # def test_asset_tag_name_field_deserialization(current_client: AtlanClient, monkeypatch):
136- # def get_name_for_id(_, __):
137- # return None
138-
139- # def get_id_for_name(_, __):
140- # return None
141-
142- # monkeypatch.setattr(
143- # pyatlan.cache.atlan_tag_cache.AtlanTagCache,
144- # "get_id_for_name",
145- # get_id_for_name,
146- # )
147-
148- # monkeypatch.setattr(
149- # pyatlan.cache.atlan_tag_cache.AtlanTagCache,
150- # "get_name_for_id",
151- # get_name_for_id,
152- # )
153- # # Simulate a `Purpose` asset with `purpose_atlan_tags` of type `AtlanTagName`
154- # purpose_asset = {
155- # "typeName": "Purpose",
156- # "attributes": {
157- # # AtlanTagName
158- # "purposeClassifications": [
159- # "some-deleted-purpose-tag-1",
160- # "some-deleted-purpose-tag-2",
161- # ],
162- # },
163- # "guid": "9f7a35f4-8d37-4273-81ec-c497a83a2472",
164- # "status": "ACTIVE",
165- # "classifications": [
166- # # AtlanTag
167- # {
168- # "typeName": "some-deleted-purpose-tag-1",
169- # "entityGuid": "82683fb9-1501-4627-a5d0-0da9be64c0d5",
170- # "entityStatus": "DELETED",
171- # "propagate": False,
172- # "removePropagationsOnEntityDelete": True,
173- # "restrictPropagationThroughLineage": True,
174- # "restrictPropagationThroughHierarchy": False,
175- # },
176- # {
177- # "typeName": "some-deleted-purpose-tag-2",
178- # "entityGuid": "82683fb9-1501-4627-a5d0-0da9be64c0d5",
179- # "entityStatus": "DELETED",
180- # "propagate": False,
181- # "removePropagationsOnEntityDelete": True,
182- # "restrictPropagationThroughLineage": True,
183- # "restrictPropagationThroughHierarchy": False,
184- # },
185- # ],
186- # }
187- # purpose = parse_obj_as(Purpose, purpose_asset)
188- # assert purpose and isinstance(purpose, Purpose)
189-
190- # # Verify that deleted tags are correctly set to `None`
191- # # assert purpose.atlan_tags == [AtlanTagName('(DELETED)')]
192- # assert purpose.atlan_tags and len(purpose.atlan_tags) == 2
193- # assert purpose.atlan_tags[0].type_name.__repr__() == f"AtlanTagName('{DELETED_}')"
194- # assert purpose.atlan_tags[1].type_name.__repr__() == f"AtlanTagName('{DELETED_}')"
195- # assert purpose.purpose_atlan_tags and len(purpose.purpose_atlan_tags) == 2
196- # assert purpose.purpose_atlan_tags[0].__repr__() == f"AtlanTagName('{DELETED_}')"
197- # assert purpose.purpose_atlan_tags[1].__repr__() == f"AtlanTagName('{DELETED_}')"
116+ # Simulate a `Purpose` asset with `purpose_atlan_tags` of type `AtlanTagName`
117+ purpose_asset = {
118+ "typeName" : "Purpose" ,
119+ "attributes" : {
120+ # AtlanTagName
121+ "purposeClassifications" : [
122+ "some-deleted-purpose-tag-1" ,
123+ "some-deleted-purpose-tag-2" ,
124+ ],
125+ },
126+ "guid" : "9f7a35f4-8d37-4273-81ec-c497a83a2472" ,
127+ "status" : "ACTIVE" ,
128+ "classifications" : [
129+ # AtlanTag
130+ {
131+ "typeName" : "some-deleted-purpose-tag-1" ,
132+ "entityGuid" : "82683fb9-1501-4627-a5d0-0da9be64c0d5" ,
133+ "entityStatus" : "DELETED" ,
134+ "propagate" : False ,
135+ "removePropagationsOnEntityDelete" : True ,
136+ "restrictPropagationThroughLineage" : True ,
137+ "restrictPropagationThroughHierarchy" : False ,
138+ },
139+ {
140+ "typeName" : "some-deleted-purpose-tag-2" ,
141+ "entityGuid" : "82683fb9-1501-4627-a5d0-0da9be64c0d5" ,
142+ "entityStatus" : "DELETED" ,
143+ "propagate" : False ,
144+ "removePropagationsOnEntityDelete" : True ,
145+ "restrictPropagationThroughLineage" : True ,
146+ "restrictPropagationThroughHierarchy" : False ,
147+ },
148+ ],
149+ }
150+ purpose = parse_obj_as (Purpose , purpose_asset )
151+ assert purpose and isinstance (purpose , Purpose )
152+
153+ # Verify that deleted tags are correctly set to `None`
154+ # assert purpose.atlan_tags == [AtlanTagName('(DELETED)')]
155+ assert purpose .atlan_tags and len (purpose .atlan_tags ) == 2
156+ assert (
157+ purpose .atlan_tags [0 ].type_name .__repr__ ()
158+ == "AtlanTagName('some-deleted-purpose-tag-1')"
159+ )
160+ assert (
161+ purpose .atlan_tags [1 ].type_name .__repr__ ()
162+ == "AtlanTagName('some-deleted-purpose-tag-2')"
163+ )
164+ assert purpose .purpose_atlan_tags and len (purpose .purpose_atlan_tags ) == 2
165+ assert (
166+ purpose .purpose_atlan_tags [0 ].__repr__ ()
167+ == "AtlanTagName('some-deleted-purpose-tag-1')"
168+ )
169+ assert (
170+ purpose .purpose_atlan_tags [1 ].__repr__ ()
171+ == "AtlanTagName('some-deleted-purpose-tag-2')"
172+ )
0 commit comments