Skip to content

Commit 39a603e

Browse files
jobselkogerrod3
authored andcommitted
Fix tests for twine 7.0.0
Assisted By: Claude Opus 4.6
1 parent 877e9e7 commit 39a603e

6 files changed

Lines changed: 45 additions & 39 deletions

File tree

pulp_python/pytest_plugin.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77

88
from pulp_python.tests.functional.constants import (
99
PYTHON_EGG_FILENAME,
10-
PYTHON_EGG_URL,
1110
PYTHON_FIXTURE_URL,
1211
PYTHON_URL,
13-
PYTHON_WHEEL_FILENAME,
14-
PYTHON_WHEEL_URL,
1512
PYTHON_XS_PROJECT_SPECIFIER,
1613
)
1714

@@ -239,12 +236,17 @@ def get_href(item):
239236

240237
@pytest.fixture(scope="session")
241238
def python_package_dist_directory(tmp_path_factory, http_get):
242-
"""Creates a temp dir to hold package distros for uploading."""
243-
dist_dir = tmp_path_factory.mktemp("dist")
244-
egg_file = dist_dir / PYTHON_EGG_FILENAME
245-
wheel_file = dist_dir / PYTHON_WHEEL_FILENAME
246-
with open(egg_file, "wb") as f:
247-
f.write(http_get(PYTHON_EGG_URL))
248-
with open(wheel_file, "wb") as f:
249-
f.write(http_get(PYTHON_WHEEL_URL))
250-
yield dist_dir, egg_file, wheel_file
239+
"""Returns a factory that downloads packages into a temp directory."""
240+
241+
def _download(*urls):
242+
dist_dir = tmp_path_factory.mktemp("dist")
243+
paths = []
244+
for url in urls:
245+
filename = url.rsplit("/", 1)[-1]
246+
path = dist_dir / filename
247+
with open(path, "wb") as f:
248+
f.write(http_get(url))
249+
paths.append(path)
250+
return (dist_dir, *paths)
251+
252+
return _download

pulp_python/tests/functional/api/test_attestations.py

Lines changed: 14 additions & 16 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():
@@ -207,24 +207,22 @@ def test_attestation_twine_upload(
207207
python_content_summary,
208208
python_empty_repo_distro,
209209
python_package_dist_directory,
210+
http_get,
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+
dist_dir = python_package_dist_directory(*(urljoin(packages_url, f) for f in filenames))[0]
217+
218+
for filename in filenames:
219+
provenance = json.loads(http_get(urljoin(packages_url, f"{filename}.provenance.json")))
220+
attestation = provenance["attestation_bundles"][0]["attestations"][0]
221+
with open(dist_dir / f"{filename}.publish.attestation", "w") as f:
222+
json.dump(attestation, f)
223+
213224
repo, distro = python_empty_repo_distro()
214225
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-
228226
username, password = "admin", "password"
229227
subprocess.run(
230228
(
@@ -245,7 +243,7 @@ def test_attestation_twine_upload(
245243
tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.pulp_href).results
246244
for task in reversed(tasks):
247245
t = monitor_task(task.pulp_href)
248-
repo_ver_href = t.created_resources[0]
246+
repo_ver_href = [r for r in t.created_resources if "versions" in r][0]
249247

250248
assert repo_ver_href.endswith("versions/2/")
251249
summary = python_content_summary(repository_version=repo_ver_href)

pulp_python/tests/functional/api/test_pypi_apis.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111
PYPI_SIMPLE_V1_JSON,
1212
PYTHON_EGG_FILENAME,
1313
PYTHON_EGG_SHA256,
14+
PYTHON_EGG_URL,
15+
PYTHON_FIXTURES_URL,
1416
PYTHON_MD_PROJECT_SPECIFIER,
1517
PYTHON_MD_PYPI_SUMMARY,
1618
PYTHON_WHEEL_FILENAME,
1719
PYTHON_WHEEL_SHA256,
20+
PYTHON_WHEEL_URL,
1821
SHELF_PYTHON_JSON,
1922
TWINE_WHEEL_FILENAME,
2023
TWINE_WHEEL_URL,
@@ -70,7 +73,7 @@ def test_package_upload(
7073
):
7174
"""Tests that packages can be uploaded."""
7275
repo, distro = python_empty_repo_distro()
73-
dist_dir, egg_file, wheel_file = python_package_dist_directory
76+
dist_dir, egg_file, wheel_file = python_package_dist_directory(PYTHON_EGG_URL, PYTHON_WHEEL_URL)
7477
url = urljoin(distro.base_url, "legacy/")
7578
response = requests.post(
7679
url,
@@ -100,7 +103,7 @@ def test_package_upload_session(
100103
"""Tests that multiple uploads will be broken up into multiple tasks."""
101104
repo, distro = python_empty_repo_distro()
102105
url = urljoin(distro.base_url, "legacy/")
103-
dist_dir, egg_file, wheel_file = python_package_dist_directory
106+
dist_dir, egg_file, wheel_file = python_package_dist_directory(PYTHON_EGG_URL, PYTHON_WHEEL_URL)
104107
session = requests.Session()
105108
response = session.post(
106109
url,
@@ -130,7 +133,7 @@ def test_package_upload_simple(
130133
"""Tests that the package upload endpoint exposed at `/simple/` works."""
131134
repo, distro = python_empty_repo_distro()
132135
url = urljoin(distro.base_url, "simple/")
133-
dist_dir, egg_file, wheel_file = python_package_dist_directory
136+
dist_dir, egg_file, wheel_file = python_package_dist_directory(PYTHON_EGG_URL, PYTHON_WHEEL_URL)
134137
response = requests.post(
135138
url,
136139
data={"sha256_digest": PYTHON_EGG_SHA256},
@@ -156,7 +159,7 @@ def test_package_upload_with_metadata(
156159
"""
157160
repo, distro = python_empty_repo_distro()
158161
url = urljoin(distro.base_url, "simple/")
159-
dist_dir, egg_file, wheel_file = python_package_dist_directory
162+
dist_dir, egg_file, wheel_file = python_package_dist_directory(PYTHON_EGG_URL, PYTHON_WHEEL_URL)
160163
response = requests.post(
161164
url,
162165
data={"sha256_digest": PYTHON_WHEEL_SHA256},
@@ -183,9 +186,14 @@ def test_twine_upload(
183186
monitor_task,
184187
):
185188
"""Tests that packages can be properly uploaded through Twine."""
189+
packages_url = urljoin(PYTHON_FIXTURES_URL, "packages/")
190+
dist_dir, _, _ = python_package_dist_directory(
191+
urljoin(packages_url, "pytz-2023.3.tar.gz"),
192+
urljoin(packages_url, "pytz-2023.3-py2.py3-none-any.whl"),
193+
)
194+
186195
repo, distro = python_empty_repo_distro()
187196
url = urljoin(distro.base_url, "legacy/")
188-
dist_dir, _, _ = python_package_dist_directory
189197
username, password = "admin", "password"
190198
subprocess.run(
191199
(
@@ -205,7 +213,7 @@ def test_twine_upload(
205213
tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.pulp_href).results
206214
for task in reversed(tasks):
207215
t = monitor_task(task.pulp_href)
208-
repo_ver_href = t.created_resources[-1]
216+
repo_ver_href = [r for r in t.created_resources if "versions" in r][0]
209217
summary = python_content_summary(repository_version=repo_ver_href)
210218
assert summary.present["python.python"]["count"] == 2
211219

pulp_python/tests/functional/api/test_upload.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_synchronous_package_upload_with_metadata(
8282
def test_legacy_upload_invalid_protocol_version(
8383
python_empty_repo_distro, python_package_dist_directory
8484
):
85-
_, egg_file, _ = python_package_dist_directory
85+
_, egg_file, _ = python_package_dist_directory(PYTHON_EGG_URL, PYTHON_WHEEL_URL)
8686
_, distro = python_empty_repo_distro()
8787
url = urljoin(distro.base_url, "legacy/")
8888
with open(egg_file, "rb") as f:
@@ -108,7 +108,7 @@ def test_legacy_upload_invalid_protocol_version(
108108

109109
@pytest.mark.parallel
110110
def test_legacy_upload_invalid_filetype(python_empty_repo_distro, python_package_dist_directory):
111-
_, egg_file, wheel_file = python_package_dist_directory
111+
_, egg_file, wheel_file = python_package_dist_directory(PYTHON_EGG_URL, PYTHON_WHEEL_URL)
112112
_, distro = python_empty_repo_distro()
113113
url = urljoin(distro.base_url, "legacy/")
114114
with open(egg_file, "rb") as f:
@@ -140,7 +140,7 @@ def test_legacy_upload_invalid_filetype(python_empty_repo_distro, python_package
140140
def test_legacy_upload_invalid_metadata_version(
141141
python_empty_repo_distro, python_package_dist_directory
142142
):
143-
_, egg_file, _ = python_package_dist_directory
143+
_, egg_file, _ = python_package_dist_directory(PYTHON_EGG_URL, PYTHON_WHEEL_URL)
144144
_, distro = python_empty_repo_distro()
145145
url = urljoin(distro.base_url, "legacy/")
146146
with open(egg_file, "rb") as f:

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)