Improve PyPI proxy test assertions for all status codes

Tests now verify the correct response for each scenario:
- 200: HTML content-type
- 404: "not found" error message
- 503: "No PyPI upstream sources configured" error message
This commit is contained in:
Mondo Diaz
2026-01-29 19:35:20 -06:00
parent 4b887d1aad
commit 8ae4d7a685

View File

@@ -38,6 +38,10 @@ class TestPyPIProxyEndpoints:
assert response.status_code in (200, 404, 503)
if response.status_code == 200:
assert "text/html" in response.headers.get("content-type", "")
elif response.status_code == 404:
assert "not found" in response.json()["detail"].lower()
else: # 503
assert "No PyPI upstream sources configured" in response.json()["detail"]
@pytest.mark.integration
def test_pypi_download_missing_upstream_param(self):
@@ -112,19 +116,21 @@ class TestPyPIPackageNormalization:
@pytest.mark.integration
def test_package_name_normalized(self):
"""Test that package names are normalized per PEP 503."""
# These should all be treated the same:
# requests, Requests, requests_, requests-
# The endpoint normalizes to lowercase with hyphens
"""Test that package names are normalized per PEP 503.
Different capitalizations/separators should all be valid paths.
The endpoint normalizes to lowercase with hyphens before lookup.
"""
with httpx.Client(base_url=get_base_url(), timeout=30.0) as client:
# Different capitalizations/separators should all be valid paths
# Returns 200/404/503 depending on sources and package availability
response = client.get("/pypi/simple/Requests/")
assert response.status_code in (200, 404, 503)
# Test various name formats - all should be valid endpoint paths
for package_name in ["Requests", "some_package", "some-package"]:
response = client.get(f"/pypi/simple/{package_name}/")
# 200 = found, 404 = not found, 503 = no sources configured
assert response.status_code in (200, 404, 503), \
f"Unexpected status {response.status_code} for {package_name}"
response = client.get("/pypi/simple/some_package/")
assert response.status_code in (200, 404, 503)
response = client.get("/pypi/simple/some-package/")
assert response.status_code in (200, 404, 503)
# Verify response is appropriate for the status code
if response.status_code == 200:
assert "text/html" in response.headers.get("content-type", "")
elif response.status_code == 503:
assert "No PyPI upstream sources configured" in response.json()["detail"]