|
11 | 11 |
|
12 | 12 | from pypi_simple import ProjectPage |
13 | 13 | from packaging.version import parse |
14 | | -from urllib.parse import urljoin, urlsplit |
| 14 | +from urllib.parse import urljoin, urlsplit, urlunsplit |
15 | 15 | from random import sample |
| 16 | +from hashlib import sha256 |
16 | 17 |
|
17 | 18 |
|
18 | 19 | def test_pull_through_install( |
@@ -182,3 +183,38 @@ def test_pull_through_local_only( |
182 | 183 | r = requests.get(url) |
183 | 184 | assert r.status_code == 404 |
184 | 185 | assert r.text == "pulp-python does not exist." |
| 186 | + |
| 187 | + |
| 188 | +@pytest.mark.parallel |
| 189 | +def test_pull_through_metadata(python_remote_factory, python_distribution_factory): |
| 190 | + """ |
| 191 | + Tests that metadata is correctly served when using pull-through. |
| 192 | +
|
| 193 | + So when requesting the metadata url according to PEP 658 you should just need to add .metadata |
| 194 | + to the end of the url path. Since pull-through includes a redirect query parameter we need to |
| 195 | + test adding .metadata to the end of the url path vs adding it to the end of redirect query. |
| 196 | + """ |
| 197 | + remote = python_remote_factory(includes=["pytz"]) |
| 198 | + distro = python_distribution_factory(remote=remote.pulp_href) |
| 199 | + |
| 200 | + url = f"{distro.base_url}simple/pytz/" |
| 201 | + project_page = ProjectPage.from_response(requests.get(url), "pytz") |
| 202 | + filename1 = "pytz-2023.2-py2.py3-none-any.whl" |
| 203 | + filename2 = "pytz-2023.3-py2.py3-none-any.whl" |
| 204 | + package1 = next(p for p in project_page.packages if p.filename == filename1) |
| 205 | + package2 = next(p for p in project_page.packages if p.filename == filename2) |
| 206 | + assert package1.has_metadata |
| 207 | + assert package2.has_metadata |
| 208 | + |
| 209 | + # The correct way to get the metadata url: add to path (uv does this) |
| 210 | + parts1 = urlsplit(package1.url) |
| 211 | + url1 = urlunsplit((parts1[0], parts1[1], parts1[2] + ".metadata", parts1[3], parts1[4])) |
| 212 | + r = requests.get(url1) |
| 213 | + assert r.status_code == 200 |
| 214 | + assert sha256(r.content).hexdigest() == package1.metadata_digests["sha256"] |
| 215 | + |
| 216 | + # The incorrect way to get the metadata url: add to end of string (pip does this) |
| 217 | + url2 = package2.url + ".metadata" |
| 218 | + r = requests.get(url2) |
| 219 | + assert r.status_code == 200 |
| 220 | + assert sha256(r.content).hexdigest() == package2.metadata_digests["sha256"] |
0 commit comments