@@ -32,6 +32,33 @@ def _create(artifact_filename, filename, content_data):
3232 return _create
3333
3434
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+
3562@pytest .fixture
3663def move_to_repository (python_bindings , monitor_task ):
3764 def _move (repo_href , content_hrefs ):
@@ -124,3 +151,51 @@ def test_metadata_repair_endpoint(
124151 assert content .packagetype == "sdist"
125152 assert content .requires_python == ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
126153 assert content .author == ""
154+
155+
156+ def test_metadata_repair_endpoint_on_demand (
157+ create_content_remote ,
158+ monitor_task ,
159+ move_to_repository ,
160+ python_bindings ,
161+ python_remote_factory ,
162+ python_repo_factory ,
163+ ):
164+ """
165+ Test repairing of package metadata via `Repositories.repair_metadata` endpoint
166+ when only RemoteArtifact is present.
167+ """
168+ python_egg_filename = "scipy-1.1.0.tar.gz"
169+ python_egg_url = urljoin (
170+ urljoin (PYTHON_FIXTURES_URL , "packages/" ), python_egg_filename
171+ )
172+ python_egg_sha256 = (
173+ "878352408424dffaa695ffedf2f9f92844e116686923ed9aa8626fc30d32cfd1"
174+ )
175+ data = {
176+ "name" : "scipy" ,
177+ "version" : "1.1.0" ,
178+ # Wrong metadata
179+ "author" : "ME" ,
180+ "packagetype" : "bdist" ,
181+ "requires_python" : ">=3.8" ,
182+ }
183+ remote = python_remote_factory (includes = ["scipy" ])
184+ repo = python_repo_factory (remote = remote )
185+
186+ content = create_content_remote (
187+ python_egg_filename , python_egg_url , python_egg_sha256 , data , remote
188+ )
189+ for field , test_value in data .items ():
190+ assert getattr (content , field ) == test_value
191+ move_to_repository (repo .pulp_href , [content .pulp_href ])
192+
193+ response = python_bindings .RepositoriesPythonApi .repair_metadata (repo .pulp_href )
194+ monitor_task (response .task )
195+
196+ new_content = python_bindings .ContentPackagesApi .read (content .pulp_href )
197+ assert new_content .author == ""
198+ assert new_content .name == "scipy"
199+ assert new_content .packagetype == "sdist"
200+ assert new_content .requires_python == ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
201+ assert new_content .version == "1.1.0"
0 commit comments