import faker import httpx import pytest from owsclient import OwsClient from owsclient.test.mock import OwsClientMock from fansifter_common.adapters.graphql_router import ( GLOBAL_PARTICIPANT_BY_GP_ID_QUERY, GraphqlRouterClient, ) @pytest.fixture def graphql_router_client(ows_client: OwsClient) -> GraphqlRouterClient: return GraphqlRouterClient(ows_client=ows_client) def test_get_global_participant_by_gp_id( graphql_router_client: GraphqlRouterClient, ows_client_mock: OwsClientMock, faker: faker.Faker, ) -> None: global_participant_id = str(faker.uuid4(cast_to=str)) name = faker.name() image_url = faker.image_url() ows_client_mock.graphql_query( "graphql-router", query=GLOBAL_PARTICIPANT_BY_GP_ID_QUERY, variables={"id": global_participant_id}, ).mock( return_value=httpx.Response( 200, json={ "data": { "globalParticipantByGpId": [ { "id": global_participant_id, "name": name, "imageUrl": image_url, }, ], }, }, ) ) result = graphql_router_client.get_global_participant_by_gp_id( global_participant_id ) assert result assert result.id == global_participant_id assert result.name == name assert result.image_url == image_url def test_get_global_participant_by_gp_id_not_found( graphql_router_client: GraphqlRouterClient, ows_client_mock: OwsClientMock, faker: faker.Faker, ) -> None: global_participant_id = str(faker.uuid4(cast_to=str)) ows_client_mock.graphql_query( "graphql-router", query=GLOBAL_PARTICIPANT_BY_GP_ID_QUERY, variables={"id": global_participant_id}, ).mock( return_value=httpx.Response( 200, json={ "data": { "globalParticipantByGpId": [], }, }, ) ) result = graphql_router_client.get_global_participant_by_gp_id( global_participant_id ) assert not result