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 ):
@@ -84,43 +117,111 @@ def test_metadata_repair_command(
84117
85118def test_metadata_repair_endpoint (
86119 create_content_direct ,
120+ create_content_remote ,
121+ delete_orphans_pre ,
87122 download_python_file ,
88123 monitor_task ,
89124 move_to_repository ,
90125 python_bindings ,
91- python_repo ,
126+ python_remote_factory ,
127+ python_repo_factory ,
92128):
93129 """
94130 Test repairing of package metadata via `Repositories.repair_metadata` endpoint.
95131 """
96- python_egg_filename = "scipy-1.1.0.tar.gz"
97- python_egg_url = urljoin (
98- urljoin (PYTHON_FIXTURES_URL , "packages/" ), python_egg_filename
132+ # 1. Setup tested data
133+ # Shared data
134+ python_remote = python_remote_factory ()
135+ python_remote_bad = python_remote_factory (url = "https://fixtures.pulpproject.org/" )
136+ python_repo = python_repo_factory (remote = python_remote )
137+
138+ # Immediate content
139+ scipy_egg_filename = "scipy-1.1.0-cp27-none-win32.whl"
140+ scipy_egg_url = urljoin (
141+ urljoin (PYTHON_FIXTURES_URL , "packages/" ), scipy_egg_filename
99142 )
100- python_file = download_python_file (python_egg_filename , python_egg_url )
143+ scipy_file = download_python_file (scipy_egg_filename , scipy_egg_url )
144+ scipy_data_0 = {
145+ "filename" : scipy_egg_filename ,
146+ "name" : "scipy" ,
147+ "version" : "1.1.0" ,
148+ # Wrong metadata
149+ "author" : "ME" ,
150+ "packagetype" : "bdist" ,
151+ "requires_python" : ">=3.8" ,
152+ }
101153
102- data = {
154+ # On-demand content
155+ celery_data = {
156+ "filename" : "celery-2.4.1.tar.gz" ,
157+ "name" : "celery" ,
158+ "version" : "2.4.1" ,
159+ "sha256" : "c77652ca179d14473975822dbfb1b5dab950c88c171ef6bc2257ddb9066e6790" ,
160+ # Wrong metadata
161+ "author" : "ME" ,
162+ "packagetype" : "bdist" ,
163+ "requires_python" : ">=3.8" ,
164+ }
165+
166+ scipy_data_1 = {
167+ "filename" : "scipy-1.1.0.tar.gz" ,
103168 "name" : "scipy" ,
169+ "version" : "1.1.0" ,
170+ "sha256" : "878352408424dffaa695ffedf2f9f92844e116686923ed9aa8626fc30d32cfd1" ,
104171 # Wrong metadata
105172 "author" : "ME" ,
106173 "packagetype" : "bdist" ,
107174 "requires_python" : ">=3.8" ,
108- "version" : "0.2" ,
109175 }
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 ])
116176
177+ scipy_data_2 = scipy_data_1 .copy ()
178+ scipy_data_2 ["filename" ] = "scipy-1.1.0-cp36-none-win32.whl"
179+ scipy_data_2 ["sha256" ] = (
180+ "0e9bb7efe5f051ea7212555b290e784b82f21ffd0f655405ac4f87e288b730b3"
181+ )
182+
183+ # 2. Create content
184+ celery_content = create_content_remote (celery_data , python_remote )
185+ scipy_content_0 = create_content_direct (scipy_file , scipy_data_0 )
186+ scipy_content_1 = create_content_remote (
187+ scipy_data_1 , python_remote , python_remote_bad
188+ )
189+ scipy_content_2 = create_content_remote (scipy_data_2 , python_remote_bad )
190+
191+ content_hrefs = {}
192+ for data , content in [
193+ (celery_data , celery_content ),
194+ (scipy_data_0 , scipy_content_0 ),
195+ (scipy_data_1 , scipy_content_1 ),
196+ (scipy_data_2 , scipy_content_2 ),
197+ ]:
198+ for field , test_value in data .items ():
199+ assert getattr (content , field ) == test_value
200+ content_hrefs [data ["filename" ]] = content .pulp_href
201+ move_to_repository (python_repo .pulp_href , list (content_hrefs .values ()))
202+
203+ # 3. Repair metadata
117204 response = python_bindings .RepositoriesPythonApi .repair_metadata (
118205 python_repo .pulp_href
119206 )
120207 monitor_task (response .task )
121208
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 == ""
209+ # 4. Check new metadata
210+ new_metadata = [
211+ # repaired
212+ ("celery-2.4.1.tar.gz" , "Ask Solem" , "sdist" , "" ),
213+ (
214+ "scipy-1.1.0-cp27-none-win32.whl" ,
215+ "" ,
216+ "bdist_wheel" ,
217+ ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" ,
218+ ),
219+ ("scipy-1.1.0.tar.gz" , "" , "sdist" , ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*" ),
220+ # not repaired
221+ ("scipy-1.1.0-cp36-none-win32.whl" , "ME" , "bdist" , ">=3.8" ),
222+ ]
223+ for filename , author , packagetype , requires_python in new_metadata :
224+ new_content = python_bindings .ContentPackagesApi .read (content_hrefs [filename ])
225+ assert new_content .author == author
226+ assert new_content .packagetype == packagetype
227+ assert new_content .requires_python == requires_python
0 commit comments