From 8ae4d7a685650f56fc8d974410b59c55063124b2 Mon Sep 17 00:00:00 2001 From: Mondo Diaz Date: Thu, 29 Jan 2026 19:35:20 -0600 Subject: [PATCH] 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 --- backend/tests/integration/test_pypi_proxy.py | 32 ++++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/backend/tests/integration/test_pypi_proxy.py b/backend/tests/integration/test_pypi_proxy.py index 61d0c91..d5c2ca2 100644 --- a/backend/tests/integration/test_pypi_proxy.py +++ b/backend/tests/integration/test_pypi_proxy.py @@ -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"]