@@ -32,6 +32,49 @@ 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 , ra_url , ra_sha256 , content_data , 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(artifact=None, 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} , url={ ra_url !r} ); " # noqa: E501
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
+
62
+ @pytest .mark .django_db
63
+ @pytest .fixture
64
+ def delete_content ():
65
+ def _delete (content_href ):
66
+ from pulpcore .plugin .util import extract_pk
67
+ from pulp_python .app .models import PythonPackageContent
68
+
69
+ content = PythonPackageContent .objects .get (pk = extract_pk (content_href ))
70
+ content .version_memberships .all ().delete ()
71
+ artifacts = content ._artifacts .all ()
72
+ content .delete ()
73
+ artifacts .delete ()
74
+
75
+ return _delete
76
+
77
+
35
78
@pytest .fixture
36
79
def move_to_repository (python_bindings , monitor_task ):
37
80
def _move (repo_href , content_hrefs ):
@@ -84,6 +127,7 @@ def test_metadata_repair_command(
84
127
85
128
def test_metadata_repair_endpoint (
86
129
create_content_direct ,
130
+ delete_content ,
87
131
download_python_file ,
88
132
monitor_task ,
89
133
move_to_repository ,
@@ -124,3 +168,54 @@ def test_metadata_repair_endpoint(
124
168
assert content .packagetype == "sdist"
125
169
assert content .requires_python == ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
126
170
assert content .author == ""
171
+ delete_content (content .pulp_href )
172
+
173
+
174
+ def test_metadata_repair_endpoint_on_demand (
175
+ create_content_remote ,
176
+ delete_content ,
177
+ monitor_task ,
178
+ move_to_repository ,
179
+ python_bindings ,
180
+ python_remote_factory ,
181
+ python_repo_factory ,
182
+ ):
183
+ """
184
+ Test repairing of package metadata via `Repositories.repair_metadata` endpoint
185
+ when only RemoteArtifact is present.
186
+ """
187
+ python_egg_filename = "scipy-1.1.0.tar.gz"
188
+ python_egg_url = urljoin (
189
+ urljoin (PYTHON_FIXTURES_URL , "packages/" ), python_egg_filename
190
+ )
191
+ python_egg_sha256 = (
192
+ "878352408424dffaa695ffedf2f9f92844e116686923ed9aa8626fc30d32cfd1"
193
+ )
194
+ data = {
195
+ "name" : "scipy" ,
196
+ "version" : "1.1.0" ,
197
+ # Wrong metadata
198
+ "author" : "ME" ,
199
+ "packagetype" : "bdist" ,
200
+ "requires_python" : ">=3.8" ,
201
+ }
202
+ remote = python_remote_factory (includes = ["scipy" ])
203
+ repo = python_repo_factory (remote = remote )
204
+
205
+ content = create_content_remote (
206
+ python_egg_filename , python_egg_url , python_egg_sha256 , data , remote
207
+ )
208
+ for field , test_value in data .items ():
209
+ assert getattr (content , field ) == test_value
210
+ move_to_repository (repo .pulp_href , [content .pulp_href ])
211
+
212
+ response = python_bindings .RepositoriesPythonApi .repair_metadata (repo .pulp_href )
213
+ monitor_task (response .task )
214
+
215
+ new_content = python_bindings .ContentPackagesApi .read (content .pulp_href )
216
+ assert new_content .author == ""
217
+ assert new_content .name == "scipy"
218
+ assert new_content .packagetype == "sdist"
219
+ assert new_content .requires_python == ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
220
+ assert new_content .version == "1.1.0"
221
+ delete_content (content .pulp_href )
0 commit comments