From b4e23d98992600cb44e6ff4e3bd0218c66ffa76a Mon Sep 17 00:00:00 2001 From: Mondo Diaz Date: Thu, 29 Jan 2026 16:00:56 -0600 Subject: [PATCH] Fix PyPI proxy tests to use ORCHARD_TEST_URL env var directly --- backend/tests/integration/test_pypi_proxy.py | 55 ++++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/backend/tests/integration/test_pypi_proxy.py b/backend/tests/integration/test_pypi_proxy.py index e3f63fe..64c69bd 100644 --- a/backend/tests/integration/test_pypi_proxy.py +++ b/backend/tests/integration/test_pypi_proxy.py @@ -1,6 +1,13 @@ """Integration tests for PyPI transparent proxy.""" +import os import pytest +import httpx + + +def get_base_url(): + """Get the base URL for the Orchard server from environment.""" + return os.environ.get("ORCHARD_TEST_URL", "http://localhost:8080") class TestPyPIProxyEndpoints: @@ -10,26 +17,29 @@ class TestPyPIProxyEndpoints: """ @pytest.mark.integration - def test_pypi_simple_index_no_sources(self, unauthenticated_client): + def test_pypi_simple_index_no_sources(self): """Test that /pypi/simple/ returns 503 when no sources configured.""" - response = unauthenticated_client.get("/pypi/simple/") - # Should return 503 when no PyPI upstream sources are configured - assert response.status_code == 503 - assert "No PyPI upstream sources configured" in response.json()["detail"] + with httpx.Client(base_url=get_base_url(), timeout=30.0) as client: + response = client.get("/pypi/simple/") + # Should return 503 when no PyPI upstream sources are configured + assert response.status_code == 503 + assert "No PyPI upstream sources configured" in response.json()["detail"] @pytest.mark.integration - def test_pypi_package_no_sources(self, unauthenticated_client): + def test_pypi_package_no_sources(self): """Test that /pypi/simple/{package}/ returns 503 when no sources configured.""" - response = unauthenticated_client.get("/pypi/simple/requests/") - assert response.status_code == 503 - assert "No PyPI upstream sources configured" in response.json()["detail"] + with httpx.Client(base_url=get_base_url(), timeout=30.0) as client: + response = client.get("/pypi/simple/requests/") + assert response.status_code == 503 + assert "No PyPI upstream sources configured" in response.json()["detail"] @pytest.mark.integration - def test_pypi_download_missing_upstream_param(self, unauthenticated_client): + def test_pypi_download_missing_upstream_param(self): """Test that /pypi/simple/{package}/{filename} requires upstream param.""" - response = unauthenticated_client.get("/pypi/simple/requests/requests-2.31.0.tar.gz") - assert response.status_code == 400 - assert "upstream" in response.json()["detail"].lower() + with httpx.Client(base_url=get_base_url(), timeout=30.0) as client: + response = client.get("/pypi/simple/requests/requests-2.31.0.tar.gz") + assert response.status_code == 400 + assert "upstream" in response.json()["detail"].lower() class TestPyPILinkRewriting: @@ -64,19 +74,20 @@ class TestPyPIPackageNormalization: """Tests for PyPI package name normalization.""" @pytest.mark.integration - def test_package_name_normalized(self, unauthenticated_client): + 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 - # Without upstream sources, we get 503, but the normalization - # happens before the source lookup - response = unauthenticated_client.get("/pypi/simple/Requests/") - assert response.status_code == 503 # No sources, but path was valid + with httpx.Client(base_url=get_base_url(), timeout=30.0) as client: + # Without upstream sources, we get 503, but the normalization + # happens before the source lookup + response = client.get("/pypi/simple/Requests/") + assert response.status_code == 503 # No sources, but path was valid - response = unauthenticated_client.get("/pypi/simple/some_package/") - assert response.status_code == 503 + response = client.get("/pypi/simple/some_package/") + assert response.status_code == 503 - response = unauthenticated_client.get("/pypi/simple/some-package/") - assert response.status_code == 503 + response = client.get("/pypi/simple/some-package/") + assert response.status_code == 503