1
1
# SPDX-License-Identifier: Apache-2.0
2
2
# Copyright 2022 Atlan Pte. Ltd.
3
3
import pytest
4
+ from pydantic .v1 import parse_obj_as
4
5
5
6
import pyatlan .cache .atlan_tag_cache
7
+ from pyatlan .model .assets import Purpose
8
+ from pyatlan .model .constants import DELETED_
6
9
from pyatlan .model .core import AtlanTagName
7
10
8
11
ATLAN_TAG_ID = "yiB7RLvdC2yeryLPjaDeHM"
@@ -62,7 +65,7 @@ def test_convert_to_display_text_when_atlan_tag_passed_returns_same_atlan_tag(
62
65
assert good_atlan_tag is AtlanTagName ._convert_to_display_text (good_atlan_tag )
63
66
64
67
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 ):
66
69
def get_name_for_id (_ ):
67
70
return None
68
71
@@ -72,8 +75,10 @@ def get_name_for_id(_):
72
75
get_name_for_id ,
73
76
)
74
77
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
+ )
77
82
78
83
79
84
def test_convert_to_display_text_when_id (monkeypatch ):
@@ -102,3 +107,68 @@ def get_id_for_name(value):
102
107
103
108
def test_json_encode_atlan_tag (monkeypatch , good_atlan_tag ):
104
109
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