Skip to content

Commit aba2b51

Browse files
committed
Fix tests for twine 7.0.0
Assisted By: Claude Opus 4.6
1 parent 877e9e7 commit aba2b51

4 files changed

Lines changed: 28 additions & 25 deletions

File tree

pulp_python/tests/functional/api/test_attestations.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import json
2-
import shutil
32
import subprocess
4-
from pathlib import Path
53
from urllib.parse import urljoin
64

75
import pytest
@@ -10,6 +8,8 @@
108

119
from 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")
1515
def 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)

pulp_python/tests/functional/api/test_pypi_apis.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
PYPI_SIMPLE_V1_JSON,
1212
PYTHON_EGG_FILENAME,
1313
PYTHON_EGG_SHA256,
14+
PYTHON_FIXTURES_URL,
1415
PYTHON_MD_PROJECT_SPECIFIER,
1516
PYTHON_MD_PYPI_SUMMARY,
1617
PYTHON_WHEEL_FILENAME,
@@ -179,21 +180,26 @@ def test_twine_upload(
179180
pulpcore_bindings,
180181
python_content_summary,
181182
python_empty_repo_distro,
182-
python_package_dist_directory,
183+
http_get,
184+
tmp_path,
183185
monitor_task,
184186
):
185187
"""Tests that packages can be properly uploaded through Twine."""
188+
packages_url = urljoin(PYTHON_FIXTURES_URL, "packages/")
189+
for filename in ("pytz-2023.3.tar.gz", "pytz-2023.3-py2.py3-none-any.whl"):
190+
with open(tmp_path / filename, "wb") as f:
191+
f.write(http_get(urljoin(packages_url, filename)))
192+
186193
repo, distro = python_empty_repo_distro()
187194
url = urljoin(distro.base_url, "legacy/")
188-
dist_dir, _, _ = python_package_dist_directory
189195
username, password = "admin", "password"
190196
subprocess.run(
191197
(
192198
"twine",
193199
"upload",
194200
"--repository-url",
195201
url,
196-
dist_dir / "*",
202+
tmp_path / "*",
197203
"-u",
198204
username,
199205
"-p",
@@ -205,7 +211,7 @@ def test_twine_upload(
205211
tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.pulp_href).results
206212
for task in reversed(tasks):
207213
t = monitor_task(task.pulp_href)
208-
repo_ver_href = t.created_resources[-1]
214+
repo_ver_href = [r for r in t.created_resources if "versions" in r][0]
209215
summary = python_content_summary(repository_version=repo_ver_href)
210216
assert summary.present["python.python"]["count"] == 2
211217

@@ -217,7 +223,7 @@ def test_twine_upload(
217223
"upload",
218224
"--repository-url",
219225
url,
220-
dist_dir / "*",
226+
tmp_path / "*",
221227
"-u",
222228
username,
223229
"-p",

pulp_python/tests/functional/assets/shelf-reader-0.1.tar.gz.publish.attestation

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)