"""Unit tests for model module.""" from datetime import date import pytest from src.models import Recipient from src.models import TriggeredSend from src.models import TriggeredSendBatchPayload @pytest.fixture def triggered_send(): """Fixture for TriggeredSend model.""" return TriggeredSend( business_unit_id='BU123', triggered_send_definition_key='DEF456', recipients=[ Recipient( email_address='test@example.com', profile_uuid='uuid-1', source_event_id='evt-1', first_name='John', last_name='Doe', postal_code='12345' ), Recipient( email_address='jane@example.com', profile_uuid='uuid-2', source_event_id='evt-2', first_name='Jane', last_name=None, postal_code=None ) ] ) class TestTriggeredSendBatchPayload: """Test suite for TriggeredSendBatchPayload model.""" def test_from_input_model(self, triggered_send): """Test from_input_model method.""" payload = TriggeredSendBatchPayload.from_input_model(triggered_send) assert isinstance(payload, TriggeredSendBatchPayload) assert len(payload.root) == 2 # Check first recipient r1 = payload.root[0].to assert r1.address == 'test@example.com' assert r1.subscriber_key == 'evt-1_DEF456' assert r1.contact_attributes.subscriber_attributes.encrypted_id == 'uuid-1' assert r1.contact_attributes.subscriber_attributes.first_name == 'John' assert r1.contact_attributes.subscriber_attributes.last_name == 'Doe' assert r1.contact_attributes.subscriber_attributes.postal_code == '12345' assert isinstance(r1.contact_attributes.subscriber_attributes.start_date, date) # Check second recipient r2 = payload.root[1].to assert r2.address == 'jane@example.com' assert r2.subscriber_key == 'evt-2_DEF456' assert r2.contact_attributes.subscriber_attributes.encrypted_id == 'uuid-2' assert r2.contact_attributes.subscriber_attributes.first_name == 'Jane' assert r2.contact_attributes.subscriber_attributes.last_name is None assert r2.contact_attributes.subscriber_attributes.postal_code is None assert isinstance(r2.contact_attributes.subscriber_attributes.start_date, date)