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:
@@ -38,6 +38,10 @@ class TestPyPIProxyEndpoints:
|
|||||||
assert response.status_code in (200, 404, 503)
|
assert response.status_code in (200, 404, 503)
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
assert "text/html" in response.headers.get("content-type", "")
|
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
|
@pytest.mark.integration
|
||||||
def test_pypi_download_missing_upstream_param(self):
|
def test_pypi_download_missing_upstream_param(self):
|
||||||
@@ -112,19 +116,21 @@ class TestPyPIPackageNormalization:
|
|||||||
|
|
||||||
@pytest.mark.integration
|
@pytest.mark.integration
|
||||||
def test_package_name_normalized(self):
|
def test_package_name_normalized(self):
|
||||||
"""Test that package names are normalized per PEP 503."""
|
"""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
|
|
||||||
|
|
||||||
|
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:
|
with httpx.Client(base_url=get_base_url(), timeout=30.0) as client:
|
||||||
# Different capitalizations/separators should all be valid paths
|
# Test various name formats - all should be valid endpoint paths
|
||||||
# Returns 200/404/503 depending on sources and package availability
|
for package_name in ["Requests", "some_package", "some-package"]:
|
||||||
response = client.get("/pypi/simple/Requests/")
|
response = client.get(f"/pypi/simple/{package_name}/")
|
||||||
assert response.status_code in (200, 404, 503)
|
# 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/")
|
# Verify response is appropriate for the status code
|
||||||
assert response.status_code in (200, 404, 503)
|
if response.status_code == 200:
|
||||||
|
assert "text/html" in response.headers.get("content-type", "")
|
||||||
response = client.get("/pypi/simple/some-package/")
|
elif response.status_code == 503:
|
||||||
assert response.status_code in (200, 404, 503)
|
assert "No PyPI upstream sources configured" in response.json()["detail"]
|
||||||
|
|||||||
Reference in New Issue
Block a user