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
7+ from pyatlan .model .assets import Purpose
8+ from pyatlan .model .constants import DELETED_
69from pyatlan .model .core import AtlanTagName
710
811ATLAN_TAG_ID = "yiB7RLvdC2yeryLPjaDeHM"
@@ -62,7 +65,7 @@ def test_convert_to_display_text_when_atlan_tag_passed_returns_same_atlan_tag(
6265 assert good_atlan_tag is AtlanTagName ._convert_to_display_text (good_atlan_tag )
6366
6467
65- def test_convert_to_display_text_when_bad_string_raises_value_error (monkeypatch ):
68+ def test_convert_to_display_text_when_bad_string (monkeypatch ):
6669 def get_name_for_id (_ ):
6770 return None
6871
@@ -72,8 +75,10 @@ def get_name_for_id(_):
7275 get_name_for_id ,
7376 )
7477
75- with pytest .raises (ValueError , match = "bad is not a valid AtlanTag" ):
76- AtlanTagName ._convert_to_display_text ("bad" )
78+ assert (
79+ AtlanTagName ._convert_to_display_text ("bad" ).__repr__ ()
80+ == f"AtlanTagName('{ DELETED_ } ')"
81+ )
7782
7883
7984def test_convert_to_display_text_when_id (monkeypatch ):
@@ -102,3 +107,68 @@ def get_id_for_name(value):
102107
103108def test_json_encode_atlan_tag (monkeypatch , good_atlan_tag ):
104109 assert AtlanTagName .json_encode_atlan_tag (good_atlan_tag ) == ATLAN_TAG_ID
110+
111+
112+ def test_asset_tag_name_field_deserialization (monkeypatch ):
113+ def get_name_for_id (_ ):
114+ return None
115+
116+ def get_id_for_name (_ ):
117+ return None
118+
119+ monkeypatch .setattr (
120+ pyatlan .cache .atlan_tag_cache .AtlanTagCache ,
121+ "get_id_for_name" ,
122+ get_id_for_name ,
123+ )
124+
125+ monkeypatch .setattr (
126+ pyatlan .cache .atlan_tag_cache .AtlanTagCache ,
127+ "get_name_for_id" ,
128+ get_name_for_id ,
129+ )
130+ # Simulate a `Purpose` asset with `purpose_atlan_tags` of type `AtlanTagName`
131+ purpose_asset = {
132+ "typeName" : "Purpose" ,
133+ "attributes" : {
134+ # AtlanTagName
135+ "purposeClassifications" : [
136+ "some-deleted-purpose-tag-1" ,
137+ "some-deleted-purpose-tag-2" ,
138+ ],
139+ },
140+ "guid" : "9f7a35f4-8d37-4273-81ec-c497a83a2472" ,
141+ "status" : "ACTIVE" ,
142+ "classifications" : [
143+ # AtlanTag
144+ {
145+ "typeName" : "some-deleted-purpose-tag-1" ,
146+ "entityGuid" : "82683fb9-1501-4627-a5d0-0da9be64c0d5" ,
147+ "entityStatus" : "DELETED" ,
148+ "propagate" : False ,
149+ "removePropagationsOnEntityDelete" : True ,
150+ "restrictPropagationThroughLineage" : True ,
151+ "restrictPropagationThroughHierarchy" : False ,
152+ },
153+ {
154+ "typeName" : "some-deleted-purpose-tag-2" ,
155+ "entityGuid" : "82683fb9-1501-4627-a5d0-0da9be64c0d5" ,
156+ "entityStatus" : "DELETED" ,
157+ "propagate" : False ,
158+ "removePropagationsOnEntityDelete" : True ,
159+ "restrictPropagationThroughLineage" : True ,
160+ "restrictPropagationThroughHierarchy" : False ,
161+ },
162+ ],
163+ }
164+ purpose = parse_obj_as (Purpose , purpose_asset )
165+ assert purpose and isinstance (purpose , Purpose )
166+
167+ # Verify that deleted tags are correctly set to `None`
168+ # assert purpose.atlan_tags == [AtlanTagName('(DELETED)')]
169+ assert purpose .atlan_tags and len (purpose .atlan_tags ) == 2
170+ assert purpose .atlan_tags [0 ].type_name .__repr__ () == f"AtlanTagName('{ DELETED_ } ')"
171+ assert purpose .atlan_tags [1 ].type_name .__repr__ () == f"AtlanTagName('{ DELETED_ } ')"
172+ assert purpose .purpose_atlan_tags and len (purpose .purpose_atlan_tags ) == 2
173+ assert purpose .purpose_atlan_tags [0 ].__repr__ () == f"AtlanTagName('{ DELETED_ } ')"
174+ assert purpose .purpose_atlan_tags [1 ].__repr__ () == f"AtlanTagName('{ DELETED_ } ')"
0 commit comments