From 4338edea7c54a4b4490cfcb65faa6928cdb5a115 Mon Sep 17 00:00:00 2001 From: Gerrod Ubben Date: Wed, 19 Feb 2025 16:30:20 -0500 Subject: [PATCH] Raise upperbound for pkginfo requirement --- CHANGES/+preliminary-md-24-support.misc | 1 + .../functional/api/test_crud_content_unit.py | 13 ++ .../tests/functional/api/test_pypi_apis.py | 136 +++++++++++------- requirements.txt | 2 +- 4 files changed, 101 insertions(+), 51 deletions(-) create mode 100644 CHANGES/+preliminary-md-24-support.misc diff --git a/CHANGES/+preliminary-md-24-support.misc b/CHANGES/+preliminary-md-24-support.misc new file mode 100644 index 00000000..7fa38ffc --- /dev/null +++ b/CHANGES/+preliminary-md-24-support.misc @@ -0,0 +1 @@ +Ensure uploading packages with metadata spec 2.4 is supported. diff --git a/pulp_python/tests/functional/api/test_crud_content_unit.py b/pulp_python/tests/functional/api/test_crud_content_unit.py index 25834bc2..f3dbe073 100644 --- a/pulp_python/tests/functional/api/test_crud_content_unit.py +++ b/pulp_python/tests/functional/api/test_crud_content_unit.py @@ -242,3 +242,16 @@ def test_upload_metadata_23_spec(python_content_factory): content = python_content_factory(filename, url=package.url) assert content.metadata_version == "2.3" break + + +@pytest.mark.parallel +def test_upload_metadata_24_spec(python_content_factory): + """Test that packages using metadata spec 2.4 can be uploaded to pulp.""" + filename = "urllib3-2.3.0-py3-none-any.whl" + with PyPISimple() as client: + page = client.get_project_page("urllib3") + for package in page.packages: + if package.filename == filename: + content = python_content_factory(filename, url=package.url) + assert content.metadata_version == "2.4" + break diff --git a/pulp_python/tests/functional/api/test_pypi_apis.py b/pulp_python/tests/functional/api/test_pypi_apis.py index 2cab07f2..421cb243 100644 --- a/pulp_python/tests/functional/api/test_pypi_apis.py +++ b/pulp_python/tests/functional/api/test_pypi_apis.py @@ -3,10 +3,11 @@ import requests import subprocess import tempfile +import pytest from urllib.parse import urljoin -from pulp_smash.pulp3.bindings import monitor_task, tasks as task_api +from pulp_smash.pulp3.bindings import monitor_task from pulp_smash.pulp3.utils import get_added_content_summary, get_content_summary from pulp_python.tests.functional.constants import ( PYTHON_CONTENT_NAME, @@ -40,6 +41,32 @@ PYPI_HOST = urljoin(HOST, PULP_PYPI_BASE_URL) +@pytest.fixture +def python_empty_repo_distro(python_repo_factory, python_distribution_factory): + """Returns an empty repo with and distribution serving it.""" + def _generate_empty_repo_distro(repo_body=None, distro_body=None): + repo_body = repo_body or {} + distro_body = distro_body or {} + repo = python_repo_factory(**repo_body) + distro = python_distribution_factory(repository=repo, **distro_body) + return repo, distro + + yield _generate_empty_repo_distro + + +@pytest.fixture(scope="module") +def python_package_dist_directory(tmp_path_factory, http_get): + """Creates a temp dir to hold package distros for uploading.""" + dist_dir = tmp_path_factory.mktemp("dist") + egg_file = dist_dir / PYTHON_EGG_FILENAME + wheel_file = dist_dir / PYTHON_WHEEL_FILENAME + with open(egg_file, "wb") as f: + f.write(http_get(PYTHON_EGG_URL)) + with open(wheel_file, "wb") as f: + f.write(http_get(PYTHON_WHEEL_URL)) + yield dist_dir, egg_file, wheel_file + + class PyPISummaryTestCase(TestCaseUsingBindings, TestHelpersMixin): """Tests the summary response of the base url of an index.""" @@ -162,18 +189,51 @@ def test_package_upload_simple(self): content = get_added_content_summary(repo, f"{repo.versions_href}1/") self.assertDictEqual({PYTHON_CONTENT_NAME: 1}, content) - def test_twine_upload(self): - """Tests that packages can be properly uploaded through Twine.""" - repo, distro = self._create_empty_repo_and_distribution() - url = urljoin(PYPI_HOST, distro.base_path + "/legacy/") - username, password = "admin", "password" + +@pytest.mark.parallel +def test_twine_upload( + pulpcore_bindings, + python_content_summary, + python_empty_repo_distro, + python_package_dist_directory, + monitor_task, +): + """Tests that packages can be properly uploaded through Twine.""" + repo, distro = python_empty_repo_distro() + url = urljoin(distro.base_url, "legacy/") + dist_dir, _, _ = python_package_dist_directory + username, password = "admin", "password" + subprocess.run( + ( + "twine", + "upload", + "--repository-url", + url, + dist_dir / "*", + "-u", + username, + "-p", + password, + ), + capture_output=True, + check=True, + ) + tasks = pulpcore_bindings.TasksApi.list(reserved_resources=repo.pulp_href).results + for task in reversed(tasks): + t = monitor_task(task.pulp_href) + repo_ver_href = t.created_resources[-1] + summary = python_content_summary(repository_version=repo_ver_href) + assert summary.present["python.python"]["count"] == 2 + + # Test re-uploading same packages gives error + with pytest.raises(subprocess.CalledProcessError): subprocess.run( ( "twine", "upload", "--repository-url", url, - self.dists_dir.name + "/*", + dist_dir / "*", "-u", username, "-p", @@ -182,50 +242,26 @@ def test_twine_upload(self): capture_output=True, check=True, ) - tasks = task_api.list(reserved_resources_record=[repo.pulp_href]).results - for task in reversed(tasks): - t = monitor_task(task.pulp_href) - repo_ver_href = t.created_resources[-1] - content = get_content_summary(repo, f"{repo_ver_href}") - self.assertDictEqual({PYTHON_CONTENT_NAME: 2}, content) - # Test re-uploading same packages gives error - with self.assertRaises(subprocess.CalledProcessError): - subprocess.run( - ( - "twine", - "upload", - "--repository-url", - url, - self.dists_dir.name + "/*", - "-u", - username, - "-p", - password, - ), - capture_output=True, - check=True, - ) - - # Test re-uploading same packages with --skip-existing works - output = subprocess.run( - ( - "twine", - "upload", - "--repository-url", - url, - self.dists_dir.name + "/*", - "-u", - username, - "-p", - password, - "--skip-existing", - ), - capture_output=True, - check=True, - text=True - ) - self.assertEqual(output.stdout.count("Skipping"), 2) + # Test re-uploading same packages with --skip-existing works + output = subprocess.run( + ( + "twine", + "upload", + "--repository-url", + url, + dist_dir / "*", + "-u", + username, + "-p", + password, + "--skip-existing", + ), + capture_output=True, + check=True, + text=True + ) + assert output.stdout.count("Skipping") == 2 class PyPISimpleApi(TestCaseUsingBindings, TestHelpersMixin): diff --git a/requirements.txt b/requirements.txt index 35d01f9c..072eff12 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ pulpcore>=3.28,<3.55 -pkginfo>=1.10.0,<1.12.0 # Twine has <1.11 in their requirements +pkginfo>=1.12.0,<1.13.0 bandersnatch>=6.1,<6.2 pypi-simple>=0.9.0,<1.0.0