1010
1111@pytest .fixture
1212def create_content_direct (python_bindings ):
13- def _create (artifact_filename , filename , content_data ):
13+ def _create (artifact_filename , content_data ):
1414 commands = (
1515 "from pulpcore.plugin.models import Artifact, ContentArtifact; "
1616 "from pulpcore.plugin.util import get_url; "
1717 "from pulp_python.app.models import PythonPackageContent; "
1818 f"a = Artifact.init_and_validate('{ artifact_filename } '); "
1919 "a.save(); "
20- f"c = PythonPackageContent(sha256=a.sha256, filename= { filename !r } , **{ content_data !r} ); " # noqa: E501
20+ f"c = PythonPackageContent(sha256=a.sha256, **{ content_data !r} ); "
2121 "c.save(); "
22- f"ca = ContentArtifact(artifact=a, content=c, relative_path={ filename !r } ); "
22+ f"ca = ContentArtifact(artifact=a, content=c, relative_path=c. filename); "
2323 "ca.save(); "
2424 "print(get_url(c))"
2525 )
@@ -32,6 +32,39 @@ 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 (content , remote , remote_2 = None ):
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(**{ content !r} ); "
43+ "c.save(); "
44+ f"ca = ContentArtifact(content=c, relative_path=c.filename); "
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=c.sha256); "
48+ "ra.save(); "
49+ )
50+ if remote_2 :
51+ commands += (
52+ f"r2 = PythonRemote.objects.get(pk=extract_pk({ remote_2 .pulp_href !r} )); "
53+ f"ra2 = RemoteArtifact(content_artifact=ca, remote=r2, sha256=c.sha256); "
54+ "ra2.save(); "
55+ )
56+ commands += "print(get_url(c))"
57+ process = subprocess .run (
58+ ["pulpcore-manager" , "shell" , "-c" , commands ], capture_output = True
59+ )
60+
61+ assert process .returncode == 0
62+ content_href = process .stdout .decode ().strip ()
63+ return python_bindings .ContentPackagesApi .read (content_href )
64+
65+ return _create
66+
67+
3568@pytest .fixture
3669def move_to_repository (python_bindings , monitor_task ):
3770 def _move (repo_href , content_hrefs ):
@@ -54,13 +87,14 @@ def test_metadata_repair_command(
5487 """Test pulpcore-manager repair-python-metadata command."""
5588 data = {
5689 "name" : "shelf-reader" ,
90+ "filename" : PYTHON_EGG_FILENAME ,
5791 # Wrong metadata
5892 "version" : "0.2" ,
5993 "packagetype" : "bdist" ,
6094 "requires_python" : ">=3.8" ,
6195 "author" : "ME" ,
6296 }
63- content = create_content_direct (python_file , PYTHON_EGG_FILENAME , data )
97+ content = create_content_direct (python_file , data )
6498 for field , wrong_value in data .items ():
6599 if field == "python_version" :
66100 continue
@@ -84,43 +118,111 @@ def test_metadata_repair_command(
84118
85119def test_metadata_repair_endpoint (
86120 create_content_direct ,
121+ create_content_remote ,
122+ delete_orphans_pre ,
87123 download_python_file ,
88124 monitor_task ,
89125 move_to_repository ,
90126 python_bindings ,
91- python_repo ,
127+ python_remote_factory ,
128+ python_repo_factory ,
92129):
93130 """
94131 Test repairing of package metadata via `Repositories.repair_metadata` endpoint.
95132 """
96- python_egg_filename = "scipy-1.1.0.tar.gz"
97- python_egg_url = urljoin (
98- urljoin (PYTHON_FIXTURES_URL , "packages/" ), python_egg_filename
133+ # 1. Setup tested data
134+ # Shared data
135+ python_remote = python_remote_factory ()
136+ python_remote_bad = python_remote_factory (url = "https://fixtures.pulpproject.org/" )
137+ python_repo = python_repo_factory (remote = python_remote )
138+
139+ # Immediate content
140+ scipy_egg_filename = "scipy-1.1.0-cp27-none-win32.whl"
141+ scipy_egg_url = urljoin (
142+ urljoin (PYTHON_FIXTURES_URL , "packages/" ), scipy_egg_filename
99143 )
100- python_file = download_python_file (python_egg_filename , python_egg_url )
144+ scipy_file = download_python_file (scipy_egg_filename , scipy_egg_url )
145+ scipy_data_0 = {
146+ "filename" : scipy_egg_filename ,
147+ "name" : "scipy" ,
148+ "version" : "1.1.0" ,
149+ # Wrong metadata
150+ "author" : "ME" ,
151+ "packagetype" : "bdist" ,
152+ "requires_python" : ">=3.8" ,
153+ }
101154
102- data = {
155+ # On-demand content
156+ celery_data = {
157+ "filename" : "celery-2.4.1.tar.gz" ,
158+ "name" : "celery" ,
159+ "version" : "2.4.1" ,
160+ "sha256" : "c77652ca179d14473975822dbfb1b5dab950c88c171ef6bc2257ddb9066e6790" ,
161+ # Wrong metadata
162+ "author" : "ME" ,
163+ "packagetype" : "bdist" ,
164+ "requires_python" : ">=3.8" ,
165+ }
166+
167+ scipy_data_1 = {
168+ "filename" : "scipy-1.1.0.tar.gz" ,
103169 "name" : "scipy" ,
170+ "version" : "1.1.0" ,
171+ "sha256" : "878352408424dffaa695ffedf2f9f92844e116686923ed9aa8626fc30d32cfd1" ,
104172 # Wrong metadata
105173 "author" : "ME" ,
106174 "packagetype" : "bdist" ,
107175 "requires_python" : ">=3.8" ,
108- "version" : "0.2" ,
109176 }
110- content = create_content_direct (python_file , python_egg_filename , data )
111- for field , wrong_value in data .items ():
112- if field == "python_version" :
113- continue
114- assert getattr (content , field ) == wrong_value
115- move_to_repository (python_repo .pulp_href , [content .pulp_href ])
116177
178+ scipy_data_2 = scipy_data_1 .copy ()
179+ scipy_data_2 ["filename" ] = "scipy-1.1.0-cp36-none-win32.whl"
180+ scipy_data_2 ["sha256" ] = (
181+ "0e9bb7efe5f051ea7212555b290e784b82f21ffd0f655405ac4f87e288b730b3"
182+ )
183+
184+ # 2. Create content
185+ celery_content = create_content_remote (celery_data , python_remote )
186+ scipy_content_0 = create_content_direct (scipy_file , scipy_data_0 )
187+ scipy_content_1 = create_content_remote (
188+ scipy_data_1 , python_remote , python_remote_bad
189+ )
190+ scipy_content_2 = create_content_remote (scipy_data_2 , python_remote_bad )
191+
192+ content_hrefs = {}
193+ for data , content in [
194+ (celery_data , celery_content ),
195+ (scipy_data_0 , scipy_content_0 ),
196+ (scipy_data_1 , scipy_content_1 ),
197+ (scipy_data_2 , scipy_content_2 ),
198+ ]:
199+ for field , test_value in data .items ():
200+ assert getattr (content , field ) == test_value
201+ content_hrefs [data ["filename" ]] = content .pulp_href
202+ move_to_repository (python_repo .pulp_href , list (content_hrefs .values ()))
203+
204+ # 3. Repair metadata
117205 response = python_bindings .RepositoriesPythonApi .repair_metadata (
118206 python_repo .pulp_href
119207 )
120208 monitor_task (response .task )
121209
122- content = python_bindings .ContentPackagesApi .read (content .pulp_href )
123- assert content .version == "1.1.0"
124- assert content .packagetype == "sdist"
125- assert content .requires_python == ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*"
126- assert content .author == ""
210+ # 4. Check new metadata
211+ new_metadata = [
212+ # repaired
213+ ("celery-2.4.1.tar.gz" , "Ask Solem" , "sdist" , "" ),
214+ (
215+ "scipy-1.1.0-cp27-none-win32.whl" ,
216+ "" ,
217+ "bdist_wheel" ,
218+ ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" ,
219+ ),
220+ ("scipy-1.1.0.tar.gz" , "" , "sdist" , ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" ),
221+ # not repaired
222+ ("scipy-1.1.0-cp36-none-win32.whl" , "ME" , "bdist" , ">=3.8" ),
223+ ]
224+ for filename , author , packagetype , requires_python in new_metadata :
225+ new_content = python_bindings .ContentPackagesApi .read (content_hrefs [filename ])
226+ assert new_content .author == author
227+ assert new_content .packagetype == packagetype
228+ assert new_content .requires_python == requires_python
0 commit comments