77import pytest
88
99from django .conf import settings
10- from pulpcore .client .pulpcore import ApiException
1110
1211
1312@pytest .fixture
@@ -21,12 +20,12 @@ def pulpcore_random_file(tmp_path):
2120 return {"name" : name , "size" : 1024 , "digest" : digest }
2221
2322
24- def _do_upload_valid_attrs (artifact_api , file , data ):
23+ def _do_upload_valid_attrs (pulpcore_bindings , file , data ):
2524 """Upload a file with the given attributes."""
26- artifact = artifact_api . create (file , ** data )
25+ artifact = pulpcore_bindings . ArtifactsApi . create (str ( file ) , ** data )
2726 # assumes ALLOWED_CONTENT_CHECKSUMS does NOT contain "md5"
2827 assert artifact .md5 is None , "MD5 {}" .format (artifact .md5 )
29- read_artifact = artifact_api .read (artifact .pulp_href )
28+ read_artifact = pulpcore_bindings . ArtifactsApi .read (artifact .pulp_href )
3029 # assumes ALLOWED_CONTENT_CHECKSUMS does NOT contain "md5"
3130 assert read_artifact .md5 is None
3231 for key , val in artifact .to_dict ().items ():
@@ -54,9 +53,7 @@ def test_upload_valid_attrs(pulpcore_bindings, pulpcore_random_file, monitor_tas
5453 monitor_task (
5554 pulpcore_bindings .OrphansCleanupApi .cleanup ({"orphan_protection_time" : 0 }).task
5655 )
57- _do_upload_valid_attrs (
58- pulpcore_bindings .ArtifactsApi , pulpcore_random_file ["name" ], data
59- )
56+ _do_upload_valid_attrs (pulpcore_bindings , pulpcore_random_file ["name" ], data )
6057
6158
6259def test_upload_empty_file (pulpcore_bindings , tmp_path , monitor_task ):
@@ -79,7 +76,7 @@ def test_upload_empty_file(pulpcore_bindings, tmp_path, monitor_task):
7976 pulpcore_bindings .OrphansCleanupApi .cleanup ({"orphan_protection_time" : 0 }).task
8077 )
8178 data = {key : file_attrs [key ] for key in keys }
82- _do_upload_valid_attrs (pulpcore_bindings . ArtifactsApi , file , data )
79+ _do_upload_valid_attrs (pulpcore_bindings , file , data )
8380
8481
8582@pytest .mark .parallel
@@ -98,16 +95,16 @@ def test_upload_invalid_attrs(pulpcore_bindings, pulpcore_random_file):
9895 for i in range (1 , len (file_attrs ) + 1 ):
9996 for keys in itertools .combinations (file_attrs , i ):
10097 data = {key : file_attrs [key ] for key in keys }
101- _do_upload_invalid_attrs (pulpcore_bindings . ArtifactsApi , pulpcore_random_file , data )
98+ _do_upload_invalid_attrs (pulpcore_bindings , pulpcore_random_file , data )
10299
103100
104- def _do_upload_invalid_attrs (artifact_api , file , data ):
101+ def _do_upload_invalid_attrs (pulpcore_bindings , file , data ):
105102 """Upload a file with the given attributes."""
106- with pytest .raises (ApiException ) as e :
107- artifact_api . create (file ["name" ], ** data )
103+ with pytest .raises (pulpcore_bindings . ApiException ) as e :
104+ pulpcore_bindings . ArtifactsApi . create (str ( file ["name" ]) , ** data )
108105
109106 assert e .value .status == 400
110- artifacts = artifact_api .list ()
107+ artifacts = pulpcore_bindings . ArtifactsApi .list ()
111108 for artifact in artifacts .results :
112109 assert artifact .sha256 != file ["digest" ]
113110
@@ -119,8 +116,8 @@ def test_upload_md5(pulpcore_bindings, pulpcore_random_file):
119116 Assumes ALLOWED_CONTENT_CHECKSUMS does NOT contain ``md5``
120117 """
121118 file_attrs = {"md5" : str (uuid .uuid4 ()), "size" : pulpcore_random_file ["size" ]}
122- with pytest .raises (ApiException ) as e :
123- pulpcore_bindings .ArtifactsApi .create (pulpcore_random_file ["name" ], ** file_attrs )
119+ with pytest .raises (pulpcore_bindings . ApiException ) as e :
120+ pulpcore_bindings .ArtifactsApi .create (str ( pulpcore_random_file ["name" ]) , ** file_attrs )
124121
125122 assert e .value .status == 400
126123
@@ -141,7 +138,7 @@ def test_upload_mixed_attrs(pulpcore_bindings, pulpcore_random_file):
141138 {"sha256" : str (uuid .uuid4 ()), "size" : pulpcore_random_file ["size" ]},
142139 )
143140 for data in invalid_data :
144- _do_upload_invalid_attrs (pulpcore_bindings . ArtifactsApi , pulpcore_random_file , data )
141+ _do_upload_invalid_attrs (pulpcore_bindings , pulpcore_random_file , data )
145142
146143
147144@pytest .mark .parallel
@@ -152,19 +149,19 @@ def test_delete_artifact(pulpcore_bindings, pulpcore_random_file, gen_user):
152149 pytest .skip ("this test only works for filesystem storage" )
153150 media_root = settings .MEDIA_ROOT
154151
155- artifact = pulpcore_bindings .ArtifactsApi .create (pulpcore_random_file ["name" ])
152+ artifact = pulpcore_bindings .ArtifactsApi .create (str ( pulpcore_random_file ["name" ]) )
156153 path_to_file = os .path .join (media_root , artifact .file )
157154 file_exists = os .path .exists (path_to_file )
158155 assert file_exists
159156
160157 # try to delete as a regular (non-admin) user
161158 regular_user = gen_user ()
162- with regular_user , pytest .raises (ApiException ) as e :
159+ with regular_user , pytest .raises (pulpcore_bindings . ApiException ) as e :
163160 pulpcore_bindings .ArtifactsApi .delete (artifact .pulp_href )
164161 assert e .value .status == 403
165162
166163 # destroy artifact api is not allowed, even for admins
167- with pytest .raises (ApiException ) as e :
164+ with pytest .raises (pulpcore_bindings . ApiException ) as e :
168165 pulpcore_bindings .ArtifactsApi .delete (artifact .pulp_href )
169166 assert e .value .status == 403
170167
@@ -173,8 +170,8 @@ def test_delete_artifact(pulpcore_bindings, pulpcore_random_file, gen_user):
173170def test_upload_artifact_as_a_regular_user (pulpcore_bindings , gen_user , pulpcore_random_file ):
174171 """Regular users do not have permission to upload artifacts."""
175172 regular_user = gen_user ()
176- with regular_user , pytest .raises (ApiException ) as e :
177- pulpcore_bindings .ArtifactsApi .create (pulpcore_random_file ["name" ])
173+ with regular_user , pytest .raises (pulpcore_bindings . ApiException ) as e :
174+ pulpcore_bindings .ArtifactsApi .create (str ( pulpcore_random_file ["name" ]) )
178175 assert e .value .status == 403
179176
180177
@@ -184,14 +181,14 @@ def test_list_and_retrieve_artifact_as_a_regular_user(
184181):
185182 """Regular users are not allowed to list and/or retrieve artifacts."""
186183 regular_user = gen_user ()
187- artifact = pulpcore_bindings .ArtifactsApi .create (pulpcore_random_file ["name" ])
184+ artifact = pulpcore_bindings .ArtifactsApi .create (str ( pulpcore_random_file ["name" ]) )
188185
189186 # check if list is not allowed
190- with regular_user , pytest .raises (ApiException ) as e :
187+ with regular_user , pytest .raises (pulpcore_bindings . ApiException ) as e :
191188 pulpcore_bindings .ArtifactsApi .list ()
192189 assert e .value .status == 403
193190
194191 # check if retrieve is also not allowed
195- with regular_user , pytest .raises (ApiException ) as e :
192+ with regular_user , pytest .raises (pulpcore_bindings . ApiException ) as e :
196193 pulpcore_bindings .ArtifactsApi .read (artifact .pulp_href )
197194 assert e .value .status == 403
0 commit comments