"""Integration tests for the tracks endpoints.""" import os import requests from tests.integration.client import OwsContributor BASE_URL = os.environ.get("QA_BASE_URL", "http://localhost:5000") class TestGetTrackParticipations: """Test GET /tracks/{tuid} endpoint.""" def test_returns_401_without_auth(self) -> None: """Test that 401 is returned without authentication.""" response = requests.get(f"{BASE_URL}/tracks/1") assert response.status_code == 401 def test_returns_404_for_unknown_track(self, client: OwsContributor) -> None: """Test that 404 is returned for unknown track IDs.""" response = requests.get( f"{BASE_URL}/tracks/999999999", headers=client._headers, ) assert response.status_code == 404 class TestBulkTrackParticipations: """Test POST /tracks/dataloader endpoint.""" def test_returns_401_without_auth(self) -> None: """Test that 401 is returned without authentication.""" response = requests.post( f"{BASE_URL}/tracks/dataloader", json={"tracks": [{"tuid": 1}]}, ) assert response.status_code == 401 def test_returns_empty_list_for_no_results(self, client: OwsContributor) -> None: """Test that empty list is returned when no tracks match. Note: Empty track list input is not a typical use case and may return 404. """ tuids = [] response = requests.post( f"{BASE_URL}/tracks/dataloader", headers=client._headers, json={"tracks": [{"tuid": tuid} for tuid in tuids]}, ) # Empty input may return 404 or empty list - both are acceptable assert response.status_code in (200, 404) def test_returns_partial_results_for_mixed_valid_invalid( self, client: OwsContributor ) -> None: """Test that invalid IDs are handled gracefully.""" invalid_tuids = [999999999, 999999998] response = requests.post( f"{BASE_URL}/tracks/dataloader", headers=client._headers, json={"tracks": [{"tuid": tuid} for tuid in invalid_tuids]}, ) # Should return 200 with empty list for non-existent tracks assert response.status_code == 200 data = response.json() assert isinstance(data, list)