"""Unit tests for response schemas.""" import pytest from pydantic import ValidationError from src.enums import TargetType from src.schemas import ( AdjustmentFileInitializeResponseData, AdjustmentFileInitializeResponseDetail, AdjustmentFileInitializeResponseMetadata, ) class TestInitializeBatchResponse: """Tests for InitializeBatchResponse schema.""" def test_valid_response_with_all_fields(self): """Test InitializeBatchResponse with all fields.""" response = AdjustmentFileInitializeResponseDetail( metadata=AdjustmentFileInitializeResponseMetadata( correlation_id='corr-123', target_id=789, target_type=TargetType.WORKSHEET_ADJUSTMENT_BATCH, ), data=AdjustmentFileInitializeResponseData( s3_bucket='test-bucket', s3_key='uploads/test.csv', ), ) assert response.metadata.target_id == 789 assert response.metadata.target_type == TargetType.WORKSHEET_ADJUSTMENT_BATCH assert response.data.s3_bucket == 'test-bucket' assert response.data.s3_key == 'uploads/test.csv' assert response.metadata.correlation_id == 'corr-123' def test_valid_response_with_correlation_id(self): """Test InitializeBatchResponse with correlation_id.""" response = AdjustmentFileInitializeResponseDetail( metadata=AdjustmentFileInitializeResponseMetadata( correlation_id='corr-456', target_id=456, target_type=TargetType.WORKSHEET_ADJUSTMENT_BATCH, ), data=AdjustmentFileInitializeResponseData( s3_bucket='my-bucket', s3_key='path/to/file.csv', ), ) assert response.metadata.target_id == 456 assert response.metadata.target_type == TargetType.WORKSHEET_ADJUSTMENT_BATCH assert response.data.s3_bucket == 'my-bucket' assert response.data.s3_key == 'path/to/file.csv' assert response.metadata.correlation_id == 'corr-456' def test_missing_target_id_raises_error(self): """Test missing target_id raises ValidationError.""" with pytest.raises(ValidationError) as exc_info: AdjustmentFileInitializeResponseMetadata( correlation_id='test', target_type=TargetType.WORKSHEET_ADJUSTMENT_BATCH, ) assert 'target_id' in str(exc_info.value) def test_missing_s3_bucket_raises_error(self): """Test missing s3_bucket raises ValidationError.""" with pytest.raises(ValidationError) as exc_info: AdjustmentFileInitializeResponseData( s3_key='key', ) assert 's3_bucket' in str(exc_info.value) def test_missing_s3_key_raises_error(self): """Test missing s3_key raises ValidationError.""" with pytest.raises(ValidationError) as exc_info: AdjustmentFileInitializeResponseData( s3_bucket='bucket', ) assert 's3_key' in str(exc_info.value) def test_invalid_target_id_type_raises_error(self): """Test invalid target_id type raises ValidationError.""" with pytest.raises(ValidationError) as exc_info: AdjustmentFileInitializeResponseMetadata( correlation_id='test', target_id='not-an-int', target_type=TargetType.WORKSHEET_ADJUSTMENT_BATCH, ) errors = exc_info.value.errors() assert any('target_id' in str(error) for error in errors) def test_model_dump_with_all_fields(self): """Test model_dump() returns correct dict with all fields.""" response = AdjustmentFileInitializeResponseDetail( metadata=AdjustmentFileInitializeResponseMetadata( correlation_id='corr-xyz', target_id=999, target_type=TargetType.WORKSHEET_ADJUSTMENT_BATCH, ), data=AdjustmentFileInitializeResponseData( s3_bucket='test-bucket', s3_key='test/key.csv', ), ) result = response.model_dump() assert result['metadata']['correlation_id'] == 'corr-xyz' assert result['metadata']['target_id'] == 999 assert result['metadata']['target_type'] == 'worksheet_flowthrough_batch' assert result['data']['s3_bucket'] == 'test-bucket' assert result['data']['s3_key'] == 'test/key.csv' def test_model_dump_with_correlation_id(self): """Test model_dump() returns correct dict with correlation_id.""" response = AdjustmentFileInitializeResponseDetail( metadata=AdjustmentFileInitializeResponseMetadata( correlation_id='corr-111', target_id=111, target_type=TargetType.WORKSHEET_ADJUSTMENT_BATCH, ), data=AdjustmentFileInitializeResponseData( s3_bucket='bucket', s3_key='key', ), ) result = response.model_dump() assert result['metadata']['correlation_id'] == 'corr-111' assert result['metadata']['target_id'] == 111 assert result['metadata']['target_type'] == 'worksheet_flowthrough_batch'