"""Integration tests for the contributors endpoints.""" import requests from tests.integration import config from tests.integration.client import OwsContributor class TestGetContributor: def test_returns_contributor( self, client: OwsContributor, contributor_uuid: str ) -> None: body = client.get_contributor(uuid=contributor_uuid) assert body["uuid"] == contributor_uuid assert "name" in body assert "label" in body def test_returns_404_when_not_found( self, client: OwsContributor, unknown_contributor_uuid: str ) -> None: client.get_contributor( uuid=unknown_contributor_uuid, expected_status_code=404, ) def test_returns_401_without_auth(self, unknown_contributor_uuid: str) -> None: response = requests.get( f"{config.QA_BASE_URL}/contributors/{unknown_contributor_uuid}", ) assert response.status_code == 401 class TestGetContributors: def test_returns_contributors( self, client: OwsContributor, contributor_uuids: list[str] ) -> None: body = client.get_contributors(uuids=contributor_uuids) returned_uuids = {contributor["uuid"] for contributor in body} assert set(contributor_uuids).issubset(returned_uuids) def test_returns_401_without_auth(self, unknown_contributor_uuid: str) -> None: response = requests.post( f"{config.QA_BASE_URL}/contributors/batch", json={"uuids": [unknown_contributor_uuid]}, ) assert response.status_code == 401 class TestCreateContributor: def test_creates_contributor(self, client: OwsContributor, vendor_id: int) -> None: body = client.create_contributor( body={ "input": {"name": "Integration Test Contributor"}, "vendor_id": vendor_id, } ) assert "uuid" in body assert body["name"] == "Integration Test Contributor" assert body["label"]["vendor_id"] == vendor_id def test_returns_403_for_unauthorized_vendor(self, client: OwsContributor) -> None: client.create_contributor( body={ "input": {"name": "Integration Test Contributor"}, "vendor_id": 99999, }, expected_status_code=403, ) def test_returns_401_without_auth(self, vendor_id: int) -> None: response = requests.post( f"{config.QA_BASE_URL}/contributors", json={ "input": {"name": "Integration Test Contributor"}, "vendor_id": vendor_id, }, ) assert response.status_code == 401 class TestUpdateContributor: def test_update_persists( self, client: OwsContributor, contributor_uuid: str ) -> None: test_isni = "0000000123456789" client.update_contributor(uuid=contributor_uuid, body={"isni": test_isni}) body = client.get_contributor(uuid=contributor_uuid) assert body["isni"] == test_isni # Restore client.update_contributor(uuid=contributor_uuid, body={"isni": None}) def test_returns_404_when_not_found( self, client: OwsContributor, unknown_contributor_uuid: str ) -> None: client.update_contributor( uuid=unknown_contributor_uuid, body={"isni": None}, expected_status_code=404, ) def test_returns_401_without_auth(self, unknown_contributor_uuid: str) -> None: response = requests.patch( f"{config.QA_BASE_URL}/contributors/{unknown_contributor_uuid}", json={"isni": None}, ) assert response.status_code == 401 class TestGetTrackParticipations: def test_returns_participations( self, client: OwsContributor, contributor_uuid: str ) -> None: body = client.get_track_participations(uuid=contributor_uuid) assert body["contributor"]["uuid"] == contributor_uuid assert isinstance(body["participations"], list) def test_returns_404_when_not_found( self, client: OwsContributor, unknown_contributor_uuid: str ) -> None: client.get_track_participations( uuid=unknown_contributor_uuid, expected_status_code=404 ) def test_returns_401_without_auth(self, unknown_contributor_uuid: str) -> None: response = requests.get( f"{config.QA_BASE_URL}/contributors/{unknown_contributor_uuid}/track-participations", ) assert response.status_code == 401 class TestGetSoundRecordingParticipations: def test_returns_participations( self, client: OwsContributor, contributor_uuid: str ) -> None: body = client.get_sound_recording_participations(uuid=contributor_uuid) assert body["contributor"]["uuid"] == contributor_uuid assert isinstance(body["participations"], list) def test_returns_404_when_not_found( self, client: OwsContributor, unknown_contributor_uuid: str ) -> None: client.get_sound_recording_participations( uuid=unknown_contributor_uuid, expected_status_code=404 ) def test_returns_401_without_auth(self, unknown_contributor_uuid: str) -> None: response = requests.get( f"{config.QA_BASE_URL}/contributors/{unknown_contributor_uuid}/sound-recording-participations", ) assert response.status_code == 401 class TestGetContributorProjects: def test_returns_projects( self, client: OwsContributor, contributor_uuid: str ) -> None: body = client.get_contributor_projects(uuid=contributor_uuid) assert body["contributor"]["uuid"] == contributor_uuid assert isinstance(body["projects"], list) def test_returns_404_when_not_found( self, client: OwsContributor, unknown_contributor_uuid: str ) -> None: client.get_contributor_projects( uuid=unknown_contributor_uuid, expected_status_code=404 ) def test_returns_401_without_auth(self, unknown_contributor_uuid: str) -> None: response = requests.get( f"{config.QA_BASE_URL}/contributors/{unknown_contributor_uuid}/projects", ) assert response.status_code == 401