11import json
2- import shutil
32import subprocess
4- from pathlib import Path
53from urllib .parse import urljoin
64
75import pytest
108
119from pulpcore .tests .functional .utils import PulpTaskError
1210
11+ from pulp_python .tests .functional .constants import PYTHON_FIXTURES_URL
12+
1313
1414@pytest .fixture (scope = "session" )
1515def twine_package ():
@@ -206,25 +206,24 @@ def test_attestation_twine_upload(
206206 pulpcore_bindings ,
207207 python_content_summary ,
208208 python_empty_repo_distro ,
209- python_package_dist_directory ,
209+ http_get ,
210+ tmp_path ,
210211 monitor_task ,
211212):
212213 """Tests that packages with attestations can be properly uploaded through Twine."""
214+ packages_url = urljoin (PYTHON_FIXTURES_URL , "packages/" )
215+ filenames = ("twine-6.2.0.tar.gz" , "twine-6.2.0-py3-none-any.whl" )
216+ for filename in filenames :
217+ with open (tmp_path / filename , "wb" ) as f :
218+ f .write (http_get (urljoin (packages_url , filename )))
219+
220+ provenance = json .loads (http_get (urljoin (packages_url , f"{ filename } .provenance.json" )))
221+ attestation = provenance ["attestation_bundles" ][0 ]["attestations" ][0 ]
222+ with open (tmp_path / f"{ filename } .publish.attestation" , "w" ) as f :
223+ json .dump (attestation , f )
224+
213225 repo , distro = python_empty_repo_distro ()
214226 url = urljoin (distro .base_url , "legacy/" )
215- dist_dir , _ , _ = python_package_dist_directory
216-
217- # Copy attestation files from test assets to dist_dir
218- assets_dir = Path (__file__ ).parent .parent / "assets"
219- attestation_files = [
220- "shelf-reader-0.1.tar.gz.publish.attestation" ,
221- "shelf_reader-0.1-py2-none-any.whl.publish.attestation" ,
222- ]
223- for attestation_file in attestation_files :
224- src = assets_dir / attestation_file
225- dst = dist_dir / attestation_file
226- shutil .copy2 (src , dst )
227-
228227 username , password = "admin" , "password"
229228 subprocess .run (
230229 (
@@ -233,7 +232,7 @@ def test_attestation_twine_upload(
233232 "--attestations" ,
234233 "--repository-url" ,
235234 url ,
236- dist_dir / "*" ,
235+ tmp_path / "*" ,
237236 "-u" ,
238237 username ,
239238 "-p" ,
@@ -245,7 +244,7 @@ def test_attestation_twine_upload(
245244 tasks = pulpcore_bindings .TasksApi .list (reserved_resources = repo .pulp_href ).results
246245 for task in reversed (tasks ):
247246 t = monitor_task (task .pulp_href )
248- repo_ver_href = t .created_resources [0 ]
247+ repo_ver_href = [ r for r in t .created_resources if "versions" in r ] [0 ]
249248
250249 assert repo_ver_href .endswith ("versions/2/" )
251250 summary = python_content_summary (repository_version = repo_ver_href )
0 commit comments