"""Integration tests for the participation roles endpoints.""" import pytest import requests from tests.integration import config from tests.integration.client import OwsContributor class TestGetRoleCategories: def test_returns_role_categories(self, client: OwsContributor) -> None: response = client.get_role_categories() assert response assert all(category.name for category in response) def test_returns_401_without_auth(self) -> None: response = requests.get( f"{config.QA_BASE_URL}/participation-roles/categories", ) assert response.status_code == 401 class TestGetBulkRolesByCategoryUuid: def test_returns_roles_by_category( self, client: OwsContributor, participation_role_category_uuids: list[str], ) -> None: response = client.get_bulk_roles_by_category_uuid( category_uuids=participation_role_category_uuids ) assert response returned_category_uuids = {str(item.category.uuid) for item in response} assert set(participation_role_category_uuids).issubset(returned_category_uuids) assert all(item.category.name for item in response) def test_returns_401_without_auth( self, participation_role_category_uuids: list[str] ) -> None: response = requests.post( f"{config.QA_BASE_URL}/participation-roles/categories/roles/dataloader", json={ "categories": [ {"uuid": uuid} for uuid in participation_role_category_uuids ] }, ) assert response.status_code == 401 class TestGetRolesByCategoryUuid: def test_returns_roles( self, client: OwsContributor, participation_role_category_uuid: str, ) -> None: response = client.get_roles_by_category_uuid( uuid=participation_role_category_uuid ) assert str(response.category.uuid) == participation_role_category_uuid assert response.category.name assert isinstance(response.roles, list) def test_returns_empty_roles_for_unknown_category( self, client: OwsContributor, unknown_participation_role_category_uuid: str, ) -> None: response = client.get_roles_by_category_uuid( uuid=unknown_participation_role_category_uuid ) assert str(response.category.uuid) == unknown_participation_role_category_uuid assert response.roles == [] def test_returns_401_without_auth( self, participation_role_category_uuid: str ) -> None: response = requests.get( f"{config.QA_BASE_URL}/participation-roles/categories/{participation_role_category_uuid}/roles", ) assert response.status_code == 401 @pytest.fixture(scope="module") def participation_role_uuid( client: OwsContributor, participation_role_category_uuid: str, ) -> str: response = client.get_roles_by_category_uuid(uuid=participation_role_category_uuid) assert response.roles return str(response.roles[0].uuid) class TestGetRoleByUuid: def test_returns_role( self, client: OwsContributor, participation_role_uuid: str, ) -> None: response = client.get_role_by_uuid(uuid=participation_role_uuid) assert response is not None assert str(response.uuid) == participation_role_uuid assert response.name assert response.category.name def test_returns_404_when_not_found( self, client: OwsContributor, unknown_participation_role_uuid: str, ) -> None: client.get_role_by_uuid( uuid=unknown_participation_role_uuid, expected_status_code=404 ) def test_returns_401_without_auth( self, unknown_participation_role_uuid: str ) -> None: response = requests.get( f"{config.QA_BASE_URL}/participation-roles/{unknown_participation_role_uuid}", ) assert response.status_code == 401