import httpx import pytest from owsclient import OwsClient from owsclient.test import OwsClientMock from app.adapters.ows_dmp import OwsDmpClient class TestOwsDmpClient: @pytest.fixture(scope="class") @classmethod def ows_client(cls) -> OwsClient: return OwsClient(environment="test", service_name="ows-dmp") @pytest.fixture(scope="class") @classmethod def client(cls, ows_client: OwsClient) -> OwsDmpClient: return OwsDmpClient(ows_client=ows_client) def test_upsert_audience_fans_calls_the_correct_endpoint( self, client: OwsDmpClient, ows_client_mock: OwsClientMock ) -> None: route = ows_client_mock.post( "ows-dmp", path="/audiences/audience-1/fans/upsert" ).mock(httpx.Response(status_code=200, json={"fanCount": 42})) client.upsert_audience_fans(audience_id="audience-1") assert route.called def test_upsert_audience_fans_returns_the_fan_count( self, client: OwsDmpClient, ows_client_mock: OwsClientMock ) -> None: ows_client_mock.post("ows-dmp", path="/audiences/audience-1/fans/upsert").mock( httpx.Response(status_code=200, json={"fanCount": 42}) ) fan_count = client.upsert_audience_fans(audience_id="audience-1") assert fan_count == 42