@@ -32,6 +32,33 @@ def _create(artifact_filename, filename, content_data):
32
32
return _create
33
33
34
34
35
+ @pytest .fixture
36
+ def create_content_remote (python_bindings ):
37
+ def _create (filename , content_data , ra_sha256 , remote ):
38
+ commands = (
39
+ "from pulpcore.plugin.models import ContentArtifact, RemoteArtifact; "
40
+ "from pulpcore.plugin.util import extract_pk, get_url; "
41
+ "from pulp_python.app.models import PythonPackageContent, PythonRemote; "
42
+ f"c = PythonPackageContent(filename={ filename !r} , **{ content_data !r} ); "
43
+ "c.save(); "
44
+ f"ca = ContentArtifact(content=c, relative_path={ filename !r} ); "
45
+ "ca.save(); "
46
+ f"r = PythonRemote.objects.get(pk=extract_pk({ remote .pulp_href !r} )); "
47
+ f"ra = RemoteArtifact(content_artifact=ca, remote=r, sha256={ ra_sha256 !r} ); "
48
+ "ra.save(); "
49
+ "print(get_url(c))"
50
+ )
51
+ process = subprocess .run (
52
+ ["pulpcore-manager" , "shell" , "-c" , commands ], capture_output = True
53
+ )
54
+
55
+ assert process .returncode == 0
56
+ content_href = process .stdout .decode ().strip ()
57
+ return python_bindings .ContentPackagesApi .read (content_href )
58
+
59
+ return _create
60
+
61
+
35
62
@pytest .fixture
36
63
def move_to_repository (python_bindings , monitor_task ):
37
64
def _move (repo_href , content_hrefs ):
@@ -84,6 +111,7 @@ def test_metadata_repair_command(
84
111
85
112
def test_metadata_repair_endpoint (
86
113
create_content_direct ,
114
+ delete_orphans_pre ,
87
115
download_python_file ,
88
116
monitor_task ,
89
117
move_to_repository ,
@@ -124,3 +152,104 @@ def test_metadata_repair_endpoint(
124
152
assert content .packagetype == "sdist"
125
153
assert content .requires_python == ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
126
154
assert content .author == ""
155
+
156
+
157
+ def test_metadata_repair_endpoint_on_demand (
158
+ create_content_remote ,
159
+ delete_orphans_pre ,
160
+ monitor_task ,
161
+ move_to_repository ,
162
+ python_bindings ,
163
+ python_remote_factory ,
164
+ python_repo_factory ,
165
+ ):
166
+ """
167
+ Test repairing of package metadata via `Repositories.repair_metadata` endpoint
168
+ when only RemoteArtifacts are present.
169
+ """
170
+ # 1. Set up tested data
171
+ python_remote = python_remote_factory ()
172
+ python_repo = python_repo_factory (remote = python_remote )
173
+
174
+ scipy_filename_1 = "scipy-1.1.0.tar.gz"
175
+ scipy_sha256_1 = "878352408424dffaa695ffedf2f9f92844e116686923ed9aa8626fc30d32cfd1"
176
+ scipy_data_1 = {
177
+ "name" : "scipy" ,
178
+ "version" : "1.1.0" ,
179
+ # Wrong metadata
180
+ "author" : "ME" ,
181
+ "packagetype" : "bdist" ,
182
+ "requires_python" : ">=3.8" ,
183
+ "sha256" : scipy_sha256_1 ,
184
+ }
185
+
186
+ scipy_filename_2 = "scipy-1.1.0-cp36-none-win32.whl"
187
+ scipy_sha256_2 = "0e9bb7efe5f051ea7212555b290e784b82f21ffd0f655405ac4f87e288b730b3"
188
+ scipy_data_2 = scipy_data_1 .copy ()
189
+ scipy_data_2 ["sha256" ] = scipy_sha256_2
190
+
191
+ celery_filename_1 = "celery-2.4.1.tar.gz"
192
+ celery_sha256_1 = "c77652ca179d14473975822dbfb1b5dab950c88c171ef6bc2257ddb9066e6790"
193
+ celery_data_1 = {
194
+ "name" : "celery" ,
195
+ "version" : "2.4.1" ,
196
+ # Wrong metadata
197
+ "author" : "ME" ,
198
+ "packagetype" : "bdist" ,
199
+ "requires_python" : ">=3.8" ,
200
+ }
201
+
202
+ celery_filename_2 = "celery-4.0.0.tar.gz"
203
+ celery_sha256_2 = "3e38a9a7f2868f774dffbb49e3afd2e56f57875deb06cb3ee3808f572601a8f0"
204
+ celery_data_2 = celery_data_1 .copy ()
205
+ celery_data_2 ["sha256" ] = celery_sha256_2
206
+ celery_data_2 ["version" ] = "4.0.0"
207
+
208
+ # 2. Create content and store its href
209
+ content_hrefs = {}
210
+ for filename , data , sha256 in [
211
+ (scipy_filename_1 , scipy_data_1 , scipy_sha256_1 ),
212
+ (scipy_filename_2 , scipy_data_2 , scipy_sha256_2 ),
213
+ (celery_filename_1 , celery_data_1 , celery_sha256_1 ),
214
+ (celery_filename_2 , celery_data_2 , celery_sha256_2 ),
215
+ ]:
216
+ content = create_content_remote (filename , data , sha256 , python_remote )
217
+ for field , test_value in data .items ():
218
+ assert getattr (content , field ) == test_value
219
+ content_hrefs [filename ] = content .pulp_href
220
+ move_to_repository (python_repo .pulp_href , list (content_hrefs .values ()))
221
+
222
+ # 3. Repair metadata
223
+ response = python_bindings .RepositoriesPythonApi .repair_metadata (
224
+ python_repo .pulp_href
225
+ )
226
+ monitor_task (response .task )
227
+
228
+ # 4. Check newly created metadata
229
+ new_metadata = [
230
+ (
231
+ "scipy-1.1.0.tar.gz" ,
232
+ "" ,
233
+ "scipy" ,
234
+ "sdist" ,
235
+ ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" ,
236
+ "1.1.0" ,
237
+ ),
238
+ (
239
+ "scipy-1.1.0-cp36-none-win32.whl" ,
240
+ "" ,
241
+ "scipy" ,
242
+ "bdist_wheel" ,
243
+ ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" ,
244
+ "1.1.0" ,
245
+ ),
246
+ ("celery-2.4.1.tar.gz" , "Ask Solem" , "celery" , "sdist" , "" , "2.4.1" ),
247
+ ("celery-4.0.0.tar.gz" , "Ask Solem" , "celery" , "sdist" , "" , "4.0.0" ),
248
+ ]
249
+ for filename , author , name , packagetype , requires_python , version in new_metadata :
250
+ new_content = python_bindings .ContentPackagesApi .read (content_hrefs [filename ])
251
+ assert new_content .author == author
252
+ assert new_content .name == name
253
+ assert new_content .packagetype == packagetype
254
+ assert new_content .requires_python == requires_python
255
+ assert new_content .version == version
0 commit comments