1
1
import os
2
2
import random
3
3
import string
4
- import random
5
4
6
5
import pytest
7
6
import requests
14
13
from pyatlan .model .enums import AnnouncementType
15
14
16
15
17
- @pytest .fixture (scope = ' module' )
16
+ @pytest .fixture (scope = " module" )
18
17
def client () -> EntityClient :
19
18
return EntityClient (AtlanClient ())
20
19
21
20
22
21
@pytest .fixture ()
23
22
def announcement () -> Announcement :
24
- return Announcement (announcement_title = "Important Announcement" ,
25
- announcement_message = 'A message' .join (random .choices (string .ascii_lowercase , k = 20 )),
26
- announcement_type = AnnouncementType .ISSUE )
23
+ return Announcement (
24
+ announcement_title = "Important Announcement" ,
25
+ announcement_message = "A message" .join (
26
+ random .choices (string .ascii_lowercase , k = 20 ) # nosec
27
+ ),
28
+ announcement_type = AnnouncementType .ISSUE ,
29
+ )
27
30
28
31
29
- @pytest .fixture (scope = ' session' )
32
+ @pytest .fixture (scope = " session" )
30
33
def atlan_host () -> str :
31
- return get_environment_variable (' ATLAN_HOST' )
34
+ return get_environment_variable (" ATLAN_HOST" )
32
35
33
36
34
- @pytest .fixture (scope = ' session' )
37
+ @pytest .fixture (scope = " session" )
35
38
def atlan_api_key () -> str :
36
- return get_environment_variable ('ATLAN_API_KEY' )
39
+ return get_environment_variable ("ATLAN_API_KEY" )
40
+
37
41
38
- @pytest .fixture (scope = ' session' )
42
+ @pytest .fixture (scope = " session" )
39
43
def headers (atlan_api_key ):
40
- return {
41
- ' accept' : ' application/json, text/plain, */*' ,
42
- ' content-type' : ' application/json' ,
43
- ' authorization' : f' Bearer { atlan_api_key } ' ,
44
+ return {
45
+ " accept" : " application/json, text/plain, */*" ,
46
+ " content-type" : " application/json" ,
47
+ " authorization" : f" Bearer { atlan_api_key } " ,
44
48
}
45
49
50
+
46
51
def get_environment_variable (name ) -> str :
47
52
ret_value = os .environ [name ]
48
53
assert ret_value
@@ -51,21 +56,23 @@ def get_environment_variable(name) -> str:
51
56
52
57
@pytest .fixture ()
53
58
def increment_counter ():
54
- i = random .randint (0 ,1000 )
59
+ i = random .randint (0 , 1000 )
60
+
55
61
def increment ():
56
62
nonlocal i
57
63
i += 1
58
64
return i
65
+
59
66
return increment
60
67
61
68
62
69
@pytest .fixture ()
63
70
def glossary_guids (atlan_host , headers ):
64
71
return get_guids (atlan_host , headers , "AtlasGlossary" )
65
72
73
+
66
74
@pytest .fixture ()
67
75
def create_glossary (atlan_host , headers , increment_counter ):
68
-
69
76
def create_it ():
70
77
suffix = increment_counter ()
71
78
url = f"{ atlan_host } /api/meta/entity/bulk"
@@ -78,20 +85,21 @@ def create_it():
78
85
"qualifiedName" : "" ,
79
86
"certificateStatus" : "DRAFT" ,
80
87
"ownersUsers" : [],
81
- "ownerGroups" : []
88
+ "ownerGroups" : [],
82
89
},
83
- "typeName" : "AtlasGlossary"
90
+ "typeName" : "AtlasGlossary" ,
84
91
}
85
92
]
86
93
}
87
94
response = requests .request ("POST" , url , headers = headers , json = payload )
88
95
response .raise_for_status ()
89
96
data = response .json ()
90
- guid = list (data [' guidAssignments' ].values ())[0 ]
97
+ guid = list (data [" guidAssignments" ].values ())[0 ]
91
98
return guid
92
99
93
100
return create_it
94
101
102
+
95
103
def get_guids (atlan_host , headers , type_name ):
96
104
url = f"{ atlan_host } /api/meta/search/indexsearch"
97
105
@@ -102,34 +110,16 @@ def get_guids(atlan_host, headers, type_name):
102
110
"query" : {
103
111
"bool" : {
104
112
"must" : [
105
- {
106
- "term" : {
107
- "__state" : "ACTIVE"
108
- }
109
- },
110
- {
111
- "prefix" : {
112
- "name.keyword" : {
113
- "value" : "Integration"
114
- }
115
- }
116
- }
113
+ {"term" : {"__state" : "ACTIVE" }},
114
+ {"prefix" : {"name.keyword" : {"value" : "Integration" }}},
117
115
]
118
116
}
119
117
},
120
118
"post_filter" : {
121
- "bool" : {
122
- "filter" : {
123
- "term" : {
124
- "__typeName.keyword" : type_name
125
- }
126
- }
127
- }
128
- }
119
+ "bool" : {"filter" : {"term" : {"__typeName.keyword" : type_name }}}
120
+ },
129
121
},
130
- "attributes" : [
131
- "connectorName"
132
- ]
122
+ "attributes" : ["connectorName" ],
133
123
}
134
124
135
125
response = requests .request ("POST" , url , headers = headers , json = payload )
@@ -146,23 +136,26 @@ def delete_asset(atlan_host, headers, guid):
146
136
response = requests .delete (url , headers = headers )
147
137
response .raise_for_status ()
148
138
139
+
149
140
def delete_assets (atlan_host , headers , type_name ):
150
141
for guid in get_guids (atlan_host , headers , type_name ):
151
142
delete_asset (atlan_host , headers , guid )
143
+
144
+
152
145
@pytest .fixture (autouse = True , scope = "module" )
153
146
def cleanup_categories (atlan_host , headers , atlan_api_key ):
154
147
delete_assets (atlan_host , headers , "AtlasGlossaryCategory" )
155
148
yield
156
149
delete_assets (atlan_host , headers , "AtlasGlossaryCategory" )
157
150
151
+
158
152
@pytest .fixture (autouse = True , scope = "module" )
159
153
def cleanup_glossaries (atlan_host , headers , atlan_api_key ):
160
154
delete_assets (atlan_host , headers , "AtlasGlossary" )
161
155
yield
162
156
delete_assets (atlan_host , headers , "AtlasGlossary" )
163
157
164
158
165
-
166
159
def test_get_glossary_by_guid_good_guid (create_glossary , client : EntityClient ):
167
160
glossary = client .get_entity_by_guid (create_glossary (), AtlasGlossary )
168
161
assert isinstance (glossary , AtlasGlossary )
@@ -171,7 +164,10 @@ def test_get_glossary_by_guid_good_guid(create_glossary, client: EntityClient):
171
164
def test_get_glossary_by_guid_bad_guid (client : EntityClient ):
172
165
with pytest .raises (AtlanServiceException ) as ex_info :
173
166
client .get_entity_by_guid ("76d54dd6-925b-499b-a455-6" , AtlasGlossary )
174
- assert 'Given instance guid 76d54dd6-925b-499b-a455-6 is invalid/not found' in ex_info .value .args [0 ]
167
+ assert (
168
+ "Given instance guid 76d54dd6-925b-499b-a455-6 is invalid/not found"
169
+ in ex_info .value .args [0 ]
170
+ )
175
171
176
172
177
173
def test_update_glossary_when_no_changes (create_glossary , client : EntityClient ):
@@ -181,7 +177,9 @@ def test_update_glossary_when_no_changes(create_glossary, client: EntityClient):
181
177
assert not response .mutated_entities
182
178
183
179
184
- def test_update_glossary_with_changes (create_glossary , client : EntityClient , announcement ):
180
+ def test_update_glossary_with_changes (
181
+ create_glossary , client : EntityClient , announcement
182
+ ):
185
183
glossary = client .get_entity_by_guid (create_glossary (), AtlasGlossary )
186
184
glossary .set_announcement (announcement )
187
185
response = client .upsert (glossary )
@@ -194,18 +192,20 @@ def test_update_glossary_with_changes(create_glossary, client: EntityClient, ann
194
192
assert glossary .attributes .announcement_title == announcement .announcement_title
195
193
196
194
197
-
198
195
def test_purge_glossary (create_glossary , client : EntityClient ):
199
196
response = client .purge_entity_by_guid (create_glossary ())
200
197
assert len (response .mutated_entities .DELETE ) == 1
201
198
assert not response .mutated_entities .UPDATE
202
199
assert not response .mutated_entities .CREATE
203
200
204
201
205
-
206
202
def test_create_glossary (client : EntityClient , increment_counter ):
207
203
glossary = AtlasGlossary (
208
- attributes = AtlasGlossary .Attributes (name = f"Integration Test Glossary { increment_counter ()} " , user_description = "This a test glossary" ))
204
+ attributes = AtlasGlossary .Attributes (
205
+ name = f"Integration Test Glossary { increment_counter ()} " ,
206
+ user_description = "This a test glossary" ,
207
+ )
208
+ )
209
209
response = client .upsert (glossary )
210
210
assert not response .mutated_entities .UPDATE
211
211
assert len (response .mutated_entities .CREATE ) == 1
@@ -217,18 +217,24 @@ def test_create_glossary(client: EntityClient, increment_counter):
217
217
def test_create_glossary_category (client : EntityClient , increment_counter ):
218
218
suffix = increment_counter ()
219
219
glossary = AtlasGlossary (
220
- attributes = AtlasGlossary .Attributes (name = f"Integration Test Glossary { suffix } " , user_description = "This a test glossary" ))
220
+ attributes = AtlasGlossary .Attributes (
221
+ name = f"Integration Test Glossary { suffix } " ,
222
+ user_description = "This a test glossary" ,
223
+ )
224
+ )
221
225
response = client .upsert (glossary )
222
226
glossary = response .mutated_entities .CREATE [0 ]
223
227
category = AtlasGlossaryCategory (
224
- attributes = AtlasGlossaryCategory .Attributes (name = f"Integration Test Glossary Category { suffix } " ,
225
- user_description = "This is a test glossary category" ,
226
- anchor = glossary )
228
+ attributes = AtlasGlossaryCategory .Attributes (
229
+ name = f"Integration Test Glossary Category { suffix } " ,
230
+ user_description = "This is a test glossary category" ,
231
+ anchor = glossary ,
232
+ )
227
233
)
228
234
response = client .upsert (category )
229
235
assert response .mutated_entities .UPDATE
230
236
assert len (response .mutated_entities .UPDATE ) == 1
231
- assert isinstance ( response .mutated_entities .UPDATE [0 ], AtlasGlossary )
237
+ assert isinstance (response .mutated_entities .UPDATE [0 ], AtlasGlossary )
232
238
assert response .mutated_entities .CREATE
233
239
assert len (response .mutated_entities .CREATE ) == 1
234
240
assert isinstance (response .mutated_entities .CREATE [0 ], AtlasGlossaryCategory )
0 commit comments