Fix PyPI proxy tests to use unauthenticated_client fixture

This commit is contained in:
Mondo Diaz
2026-01-29 15:51:29 -06:00
parent 810e024d09
commit aa3bd05d46

View File

@@ -1,7 +1,6 @@
"""Integration tests for PyPI transparent proxy."""
import pytest
import httpx
class TestPyPIProxyEndpoints:
@@ -11,28 +10,24 @@ class TestPyPIProxyEndpoints:
"""
@pytest.mark.integration
def test_pypi_simple_index_no_sources(self):
def test_pypi_simple_index_no_sources(self, unauthenticated_client):
"""Test that /pypi/simple/ returns 503 when no sources configured."""
# Use unauthenticated client since PyPI proxy is public
with httpx.Client(base_url="http://localhost:8080") as client:
response = client.get("/pypi/simple/")
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"]
@pytest.mark.integration
def test_pypi_package_no_sources(self):
def test_pypi_package_no_sources(self, unauthenticated_client):
"""Test that /pypi/simple/{package}/ returns 503 when no sources configured."""
with httpx.Client(base_url="http://localhost:8080") as client:
response = client.get("/pypi/simple/requests/")
response = unauthenticated_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):
def test_pypi_download_missing_upstream_param(self, unauthenticated_client):
"""Test that /pypi/simple/{package}/{filename} requires upstream param."""
with httpx.Client(base_url="http://localhost:8080") as client:
response = client.get("/pypi/simple/requests/requests-2.31.0.tar.gz")
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()
@@ -69,20 +64,19 @@ class TestPyPIPackageNormalization:
"""Tests for PyPI package name normalization."""
@pytest.mark.integration
def test_package_name_normalized(self):
def test_package_name_normalized(self, unauthenticated_client):
"""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
with httpx.Client(base_url="http://localhost:8080") as client:
# Without upstream sources, we get 503, but the normalization
# happens before the source lookup
response = client.get("/pypi/simple/Requests/")
response = unauthenticated_client.get("/pypi/simple/Requests/")
assert response.status_code == 503 # No sources, but path was valid
response = client.get("/pypi/simple/some_package/")
response = unauthenticated_client.get("/pypi/simple/some_package/")
assert response.status_code == 503
response = client.get("/pypi/simple/some-package/")
response = unauthenticated_client.get("/pypi/simple/some-package/")
assert response.status_code == 503