3
3
See: https://issues.redhat.com/browse/AAH-1303
4
4
5
5
"""
6
+ from time import sleep
7
+
6
8
import pytest
9
+
7
10
from ansible .errors import AnsibleError
8
11
12
+ from galaxykit .repositories import search_collection
13
+
14
+ from ..utils .repo_management_utils import upload_new_artifact
15
+ from ..utils .iqe_utils import is_stage_environment
9
16
from ..utils import (
10
- build_collection as galaxy_build_collection ,
11
17
get_all_namespaces ,
12
18
get_client ,
13
19
generate_unused_namespace ,
14
- wait_for_all_tasks ,
15
- wait_for_task ,
16
20
)
17
21
22
+ from ..utils .tasks import wait_for_all_tasks_gk
23
+ from ..utils .tools import generate_random_string
24
+
18
25
19
26
pytestmark = pytest .mark .qa # noqa: F821
20
27
@@ -173,46 +180,40 @@ def test_namespace_edit_with_user(ansible_config, user_property):
173
180
174
181
@pytest .mark .namespace
175
182
@pytest .mark .all
176
- def test_namespace_edit_logo (ansible_config ):
177
-
178
- config = ansible_config ("admin" )
179
- api_client = get_client (config , request_token = True , require_auth = True )
180
- api_prefix = config .get ("api_prefix" ).rstrip ("/" )
181
-
182
- new_namespace = generate_unused_namespace (api_client = api_client )
183
-
183
+ def test_namespace_edit_logo (galaxy_client ):
184
+ gc = galaxy_client ("admin" )
185
+ new_namespace = f"ns_test_{ generate_random_string ()} "
184
186
payload = {
185
187
'name' : new_namespace ,
186
188
}
187
- my_namespace = api_client ( f' { api_prefix } / _ui/v1/my-namespaces/' , args = payload , method = 'POST' )
189
+ my_namespace = gc . post ( " _ui/v1/my-namespaces/" , body = payload )
188
190
assert my_namespace ["avatar_url" ] == ''
189
191
190
- namespaces = api_client (f'{ api_prefix } /_ui/v1/my-namespaces/' )
191
-
192
+ namespaces = gc .get ('_ui/v1/my-namespaces/' )
192
193
name = my_namespace ["name" ]
193
194
194
195
payload = {
195
196
"name" : name ,
196
- "avatar_url" : "http://placekitten.com/400/400"
197
+ # "avatar_url": "http://placekitten.com/400/400"
198
+ "avatar_url" : "https://avatars.githubusercontent.com/u/1869705?v=4"
197
199
}
198
- api_client (f'{ api_prefix } /_ui/v1/my-namespaces/{ name } /' , args = payload , method = 'PUT' )
199
-
200
- wait_for_all_tasks (api_client )
201
- updated_namespace = api_client (f'{ api_prefix } /_ui/v1/my-namespaces/{ name } /' )
200
+ gc .put (f"_ui/v1/my-namespaces/{ name } /" , body = payload )
201
+ wait_for_all_tasks_gk (gc )
202
+ updated_namespace = gc .get (f'_ui/v1/my-namespaces/{ name } /' )
202
203
assert updated_namespace ["avatar_url" ] != ""
203
204
204
205
payload = {
205
206
"name" : name ,
206
- "avatar_url" : "http://placekitten.com/123/456"
207
+ # "avatar_url": "http://placekitten.com/123/456"
208
+ "avatar_url" : "https://avatars.githubusercontent.com/u/481677?v=4"
207
209
}
208
- resp = api_client (f'{ api_prefix } /_ui/v1/my-namespaces/{ name } /' , args = payload , method = 'PUT' )
209
-
210
- wait_for_all_tasks (api_client )
211
- updated_again_namespace = api_client (f'{ api_prefix } /_ui/v1/my-namespaces/{ name } /' )
210
+ gc .put (f"_ui/v1/my-namespaces/{ name } /" , body = payload )
211
+ wait_for_all_tasks_gk (gc )
212
+ updated_again_namespace = gc .get (f"_ui/v1/my-namespaces/{ name } /" )
212
213
assert updated_namespace ["avatar_url" ] != updated_again_namespace ["avatar_url" ]
213
214
214
215
# verify no additional namespaces are created
215
- resp = api_client ( f' { api_prefix } / _ui/v1/my-namespaces/' )
216
+ resp = gc . get ( " _ui/v1/my-namespaces/" )
216
217
assert resp ["meta" ]["count" ] == namespaces ["meta" ]["count" ]
217
218
218
219
# verify no side effects
@@ -225,65 +226,47 @@ def test_namespace_edit_logo(ansible_config):
225
226
assert my_namespace [field ] != updated_again_namespace [field ]
226
227
227
228
228
- def _test_namespace_logo_propagates_to_collections (ansible_config , upload_artifact , is_insights ):
229
- admin_config = ansible_config ("admin" )
230
- api_prefix = admin_config .get ("api_prefix" ).rstrip ("/" )
231
- api_client = get_client (admin_config , request_token = True , require_auth = True )
232
-
233
- namespace_name = generate_unused_namespace (api_client = api_client )
234
-
235
- # create empty namespace
229
+ def _test_namespace_logo_propagates_to_collections (galaxy_client , is_insights ):
230
+ gc = galaxy_client ("admin" )
231
+ namespace_name = f"ns_test_{ generate_random_string ()} "
236
232
payload = {
237
233
'name' : namespace_name
238
234
}
239
- my_namespace = api_client (f'{ api_prefix } /_ui/v1/my-namespaces/' , args = payload , method = 'POST' )
240
- wait_for_all_tasks (api_client )
235
+ my_namespace = gc .post ("_ui/v1/my-namespaces/" , body = payload )
241
236
assert my_namespace ["avatar_url" ] == ''
242
237
assert my_namespace ["avatar_sha256" ] is None
243
238
assert my_namespace ["metadata_sha256" ] is not None
244
239
245
- artifact = galaxy_build_collection (namespace = namespace_name )
240
+ artifact = upload_new_artifact (
241
+ gc , namespace_name , "published" , "1.0.1" , tags = ["application" ]
242
+ )
243
+ if is_stage_environment ():
244
+ sleep (90 )
246
245
247
- # upload collection to namespace
248
- upload_task = upload_artifact (admin_config , api_client , artifact )
249
- resp = wait_for_task (api_client , upload_task )
250
- assert resp ["state" ] == "completed"
246
+ resp = search_collection (gc , namespace = namespace_name , name = artifact .name )
251
247
252
- # verify cv index is correct
253
- search_url = (
254
- api_prefix
255
- + '/v3/plugin/ansible/search/collection-versions/'
256
- + f'?namespace={ namespace_name } &name={ artifact .name } '
257
- )
258
- resp = api_client .request (search_url )
259
248
assert resp ['data' ][0 ]['namespace_metadata' ]["avatar_url" ] is None
260
249
261
250
# upload logo to namespace
262
251
payload = {
263
252
"name" : namespace_name ,
264
- "avatar_url" : "http://placekitten.com/123/456"
253
+ # "avatar_url": "http://placekitten.com/123/456"
254
+ "avatar_url" : "https://avatars.githubusercontent.com/u/1869705?v=4"
265
255
}
266
- api_client (f'{ api_prefix } /_ui/v1/my-namespaces/{ namespace_name } /' , args = payload , method = 'PUT' )
267
- wait_for_all_tasks (api_client )
256
+ gc .put (f"_ui/v1/my-namespaces/{ namespace_name } /" , body = payload )
257
+ if is_stage_environment ():
258
+ sleep (90 )
259
+ wait_for_all_tasks_gk (gc )
268
260
269
261
# namespace logo was updated correctly
270
- my_namespace = api_client (f'{ api_prefix } / _ui/v1/my-namespaces/{ namespace_name } /' )
262
+ my_namespace = gc . get (f'_ui/v1/my-namespaces/{ namespace_name } /' )
271
263
assert my_namespace ["avatar_url" ] is not None
272
264
273
- search_url = (
274
- api_prefix
275
- + '/v3/plugin/ansible/search/collection-versions/'
276
- + f'?namespace={ namespace_name } &name={ artifact .name } '
277
- )
278
- resp = api_client (search_url )
265
+ resp = search_collection (gc , namespace = namespace_name , name = artifact .name )
279
266
cv_namespace_metadata = resp ['data' ][0 ]['namespace_metadata' ]
280
-
281
- namespace_metadata = api_client (
282
- api_prefix
283
- + '/pulp/api/v3/content/ansible/namespaces/'
284
- f'?name={ namespace_name } &ordering=-pulp_created'
285
- )['results' ][0 ]
286
-
267
+ resp = gc .get (f"pulp/api/v3/content/ansible/namespaces/"
268
+ f"?name={ namespace_name } &ordering=-pulp_created" )
269
+ namespace_metadata = resp ['results' ][0 ]
287
270
# verify that collection is using latest namespace avatar
288
271
assert cv_namespace_metadata ['avatar_url' ] == namespace_metadata ['avatar_url' ]
289
272
@@ -300,36 +283,27 @@ def _test_namespace_logo_propagates_to_collections(ansible_config, upload_artifa
300
283
"name" : namespace_name ,
301
284
"description" : "hehe hihi haha" ,
302
285
"company" : "RedHat Inc." ,
303
- "avatar_url" : "http://placekitten.com/654/321"
286
+ # "avatar_url": "http://placekitten.com/654/321"
287
+ "avatar_url" : "https://avatars.githubusercontent.com/u/481677?v=4"
304
288
}
305
- api_client (
306
- f'{ api_prefix } /_ui/v1/my-namespaces/{ namespace_name } /' ,
307
- args = payload ,
308
- method = 'PUT'
309
- )
289
+ gc .put (f"_ui/v1/my-namespaces/{ namespace_name } /" , body = payload )
290
+ if is_stage_environment ():
291
+ sleep (90 )
310
292
assert my_namespace ["avatar_sha256" ] is not None
311
293
assert my_namespace ["metadata_sha256" ] is not None
312
- wait_for_all_tasks ( api_client )
294
+ wait_for_all_tasks_gk ( gc )
313
295
314
- my_namespace = api_client (f'{ api_prefix } / _ui/v1/my-namespaces/{ namespace_name } /' )
296
+ my_namespace = gc . get (f'_ui/v1/my-namespaces/{ namespace_name } /' )
315
297
316
298
# verify cv metadata are latest and correct
317
- search_url = (
318
- api_prefix
319
- + '/v3/plugin/ansible/search/collection-versions/'
320
- + f'?namespace={ namespace_name } &name={ artifact .name } '
321
- )
322
- resp = api_client (search_url )
299
+ resp = search_collection (gc , namespace = namespace_name , name = artifact .name )
323
300
cv_namespace_metadata = resp ['data' ][0 ]['namespace_metadata' ]
324
301
assert cv_namespace_metadata ["description" ] == "hehe hihi haha"
325
302
assert cv_namespace_metadata ["company" ] == "RedHat Inc."
326
303
327
- namespace_metadata = api_client (
328
- api_prefix
329
- + '/pulp/api/v3/content/ansible/namespaces/'
330
- f'?name={ namespace_name } &ordering=-pulp_created'
331
- )['results' ][0 ]
332
-
304
+ resp = gc .get (f"pulp/api/v3/content/ansible/namespaces/"
305
+ f"?name={ namespace_name } &ordering=-pulp_created" )
306
+ namespace_metadata = resp ["results" ][0 ]
333
307
# verify cv idnex is using latest matedata
334
308
assert cv_namespace_metadata ['avatar_url' ] == namespace_metadata ['avatar_url' ]
335
309
@@ -340,11 +314,11 @@ def _test_namespace_logo_propagates_to_collections(ansible_config, upload_artifa
340
314
@pytest .mark .namespace
341
315
@pytest .mark .deployment_community
342
316
@pytest .mark .deployment_standalone
343
- def test_namespace_logo_propagates_to_collections (ansible_config , upload_artifact ):
344
- _test_namespace_logo_propagates_to_collections (ansible_config , upload_artifact , False )
317
+ def test_namespace_logo_propagates_to_collections (galaxy_client ):
318
+ _test_namespace_logo_propagates_to_collections (galaxy_client , False )
345
319
346
320
347
321
@pytest .mark .namespace
348
322
@pytest .mark .deployment_cloud
349
- def test_insights_namespace_logo_propagates_to_collections (ansible_config , upload_artifact ):
350
- _test_namespace_logo_propagates_to_collections (ansible_config , upload_artifact , True )
323
+ def test_insights_namespace_logo_propagates_to_collections (galaxy_client ):
324
+ _test_namespace_logo_propagates_to_collections (galaxy_client , True )
0 commit comments