import json import httpx import pytest from owsclient import OwsClient from owsclient.test import OwsClientMock from app.adapters.ows_text_campaigns import OwsTextCampaignsClient from app.types import PersonalizedAttributes class TestOwsTextCampaignsClient: @pytest.fixture(scope="class") @classmethod def ows_client(cls) -> OwsClient: return OwsClient(environment="test", service_name="ows-text-campaigns") @pytest.fixture(scope="class") @classmethod def client(cls, ows_client: OwsClient) -> OwsTextCampaignsClient: return OwsTextCampaignsClient(ows_client=ows_client) def test_render_messages_batch_returns_empty_list_without_a_call( self, client: OwsTextCampaignsClient ) -> None: result = client.render_messages_batch(campaign_id="campaign-1", attributes=[]) assert result == [] def test_render_messages_batch_calls_the_correct_endpoint( self, client: OwsTextCampaignsClient, ows_client_mock: OwsClientMock ) -> None: route = ows_client_mock.post( "ows-text-campaigns", path="/campaigns/campaign-1/messages/batch-render" ).mock( httpx.Response( status_code=200, json=[ { "fan_id": "fan-1", "channel": "SMS", "recipient": "+15550001111", "sender": "+15550002222", "message": "hi", "media_url": None, } ], ) ) attributes: list[PersonalizedAttributes] = [ {"fan_id": "fan-1", "phone_number": "+15550001111", "channel": "SMS"} ] result = client.render_messages_batch( campaign_id="campaign-1", attributes=attributes ) assert route.called sent_body = json.loads(route.calls.last.request.content) assert sent_body == {"personalized_attributes": attributes} assert len(result) == 1 assert result[0].fan_id == "fan-1" assert result[0].recipient == "+15550001111" assert result[0].sender == "+15550002222"