Skip to content

Commit 818d6ad

Browse files
committed
Add data-dist-info-metadata to Simple HTML API
1 parent f096946 commit 818d6ad

File tree

3 files changed

+66
-22
lines changed

3 files changed

+66
-22
lines changed

pulp_python/app/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
</html>
3636
"""
3737

38+
# TODO in the future: data-requires-python (PEP 503)
39+
# TODO now: strip empty lines
3840
simple_detail_template = """<!DOCTYPE html>
3941
<html>
4042
<head>
@@ -44,7 +46,11 @@
4446
<body>
4547
<h1>Links for {{ project_name }}</h1>
4648
{% for pkg in project_packages %}
47-
<a href="{{ pkg.url }}#sha256={{ pkg.sha256 }}" rel="internal">{{ pkg.filename }}</a><br/>
49+
<a href="{{ pkg.url }}#sha256={{ pkg.sha256 }}"
50+
{% if pkg.metadata_sha256 %}
51+
data-dist-info-metadata="sha256={{ pkg.metadata_sha256 }}"
52+
{% endif %}
53+
rel="internal">{{ pkg.filename }}</a><br/>
4854
{% endfor %}
4955
</body>
5056
</html>

pulp_python/tests/functional/api/test_pypi_apis.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
from pulp_python.tests.functional.constants import (
88
PYPI_SERIAL_CONSTANT,
9-
PYTHON_SM_PROJECT_SPECIFIER,
10-
PYTHON_SM_FIXTURE_RELEASES,
11-
PYTHON_SM_FIXTURE_CHECKSUMS,
129
PYTHON_MD_PROJECT_SPECIFIER,
1310
PYTHON_MD_PYPI_SUMMARY,
1411
PYTHON_EGG_FILENAME,
@@ -20,8 +17,6 @@
2017
SHELF_PYTHON_JSON,
2118
)
2219

23-
from pulp_python.tests.functional.utils import ensure_simple
24-
2520

2621
PYPI_LAST_SERIAL = "X-PYPI-LAST-SERIAL"
2722

@@ -243,22 +238,6 @@ def test_simple_redirect_with_publications(
243238
assert response.url == str(urljoin(pulp_content_url, f"{distro.base_path}/simple/"))
244239

245240

246-
@pytest.mark.parallel
247-
def test_simple_correctness_live(
248-
python_remote_factory, python_repo_with_sync, python_distribution_factory
249-
):
250-
"""Checks that the simple api on live distributions are correct."""
251-
remote = python_remote_factory(includes=PYTHON_SM_PROJECT_SPECIFIER)
252-
repo = python_repo_with_sync(remote)
253-
distro = python_distribution_factory(repository=repo)
254-
proper, msgs = ensure_simple(
255-
urljoin(distro.base_url, "simple/"),
256-
PYTHON_SM_FIXTURE_RELEASES,
257-
sha_digests=PYTHON_SM_FIXTURE_CHECKSUMS,
258-
)
259-
assert proper is True, msgs
260-
261-
262241
@pytest.mark.parallel
263242
def test_pypi_json(python_remote_factory, python_repo_with_sync, python_distribution_factory):
264243
"""Checks the data of `pypi/{package_name}/json` endpoint."""

pulp_python/tests/functional/api/test_pypi_simple_api.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@
88
PYTHON_EGG_FILENAME,
99
PYTHON_EGG_SHA256,
1010
PYTHON_EGG_URL,
11+
PYTHON_SM_FIXTURE_CHECKSUMS,
12+
PYTHON_SM_FIXTURE_RELEASES,
1113
PYTHON_SM_PROJECT_SPECIFIER,
1214
PYTHON_WHEEL_FILENAME,
1315
PYTHON_WHEEL_METADATA_SHA256,
1416
PYTHON_WHEEL_SHA256,
1517
PYTHON_WHEEL_URL,
18+
PYTHON_XS_FIXTURE_CHECKSUMS,
1619
)
20+
from pulp_python.tests.functional.utils import ensure_simple
1721

1822
API_VERSION = "1.1"
1923

@@ -22,6 +26,61 @@
2226
PYPI_SIMPLE_V1_JSON = "application/vnd.pypi.simple.v1+json"
2327

2428

29+
@pytest.mark.parallel
30+
def test_simple_html_index_api(
31+
python_remote_factory, python_repo_with_sync, python_distribution_factory
32+
):
33+
remote = python_remote_factory(includes=PYTHON_SM_PROJECT_SPECIFIER)
34+
repo = python_repo_with_sync(remote)
35+
distro = python_distribution_factory(repository=repo)
36+
37+
url = urljoin(distro.base_url, "simple/")
38+
headers = {"Accept": PYPI_SIMPLE_V1_HTML}
39+
40+
response = requests.get(url, headers=headers)
41+
assert response.headers["Content-Type"] == PYPI_SIMPLE_V1_HTML
42+
assert response.headers["X-PyPI-Last-Serial"] == str(PYPI_SERIAL_CONSTANT)
43+
44+
proper, msgs = ensure_simple(
45+
url, PYTHON_SM_FIXTURE_RELEASES, sha_digests=PYTHON_SM_FIXTURE_CHECKSUMS
46+
)
47+
assert proper, f"Simple API validation failed: {msgs}"
48+
49+
50+
def test_simple_html_detail_api(
51+
delete_orphans_pre,
52+
monitor_task,
53+
python_bindings,
54+
python_content_factory,
55+
python_distribution_factory,
56+
python_repo_factory,
57+
):
58+
content_1 = python_content_factory(PYTHON_WHEEL_FILENAME, url=PYTHON_WHEEL_URL)
59+
content_2 = python_content_factory(PYTHON_EGG_FILENAME, url=PYTHON_EGG_URL)
60+
body = {"add_content_units": [content_1.pulp_href, content_2.pulp_href]}
61+
62+
repo = python_repo_factory()
63+
monitor_task(python_bindings.RepositoriesPythonApi.modify(repo.pulp_href, body).task)
64+
distro = python_distribution_factory(repository=repo)
65+
66+
url = f'{urljoin(distro.base_url, "simple/")}shelf-reader'
67+
headers = {"Accept": PYPI_SIMPLE_V1_HTML}
68+
69+
response = requests.get(url, headers=headers)
70+
assert response.headers["Content-Type"] == PYPI_SIMPLE_V1_HTML
71+
assert response.headers["X-PyPI-Last-Serial"] == str(PYPI_SERIAL_CONSTANT)
72+
73+
proper, msgs = ensure_simple(
74+
urljoin(distro.base_url, "simple/"),
75+
{"shelf-reader": [PYTHON_WHEEL_FILENAME, PYTHON_EGG_FILENAME]},
76+
sha_digests=PYTHON_XS_FIXTURE_CHECKSUMS,
77+
)
78+
assert proper, f"Simple API validation failed: {msgs}"
79+
80+
html_content = response.text
81+
assert f'data-dist-info-metadata="sha256={PYTHON_WHEEL_METADATA_SHA256}' in html_content
82+
83+
2584
@pytest.mark.parallel
2685
def test_simple_json_index_api(
2786
python_remote_factory, python_repo_with_sync, python_distribution_factory

0 commit comments

Comments
 (0)