"""Unit tests for response schemas.""" import pytest from pydantic import ValidationError from file_upload_initialize.schemas.events import ( EventBridgeDetail, ) from file_upload_initialize.schemas.responses import ProcessorResponse class TestProcessorResponse: """Tests for ProcessorResponse model.""" def test_valid_response(self): """Test creating ProcessorResponse.""" api_response = {'message': 'File processed successfully'} detail = EventBridgeDetail( bucket={'name': 'test-bucket'}, object={'key': 'test/file.txt'} ) response = ProcessorResponse(detail=detail, apiResponse=api_response) assert response.detail.bucket.name == 'test-bucket' assert response.detail.object.key == 'test/file.txt' assert response.apiResponse == api_response def test_api_response_required(self): """Test ProcessorResponse requires apiResponse field.""" detail = EventBridgeDetail( bucket={'name': 'test-bucket'}, object={'key': 'test/file.txt'} ) with pytest.raises(ValidationError) as exc_info: ProcessorResponse(detail=detail) errors = exc_info.value.errors() assert any(error['loc'] == ('apiResponse',) for error in errors) def test_detail_required(self): """Test ProcessorResponse requires detail field.""" api_response = {'message': 'File processed successfully'} with pytest.raises(ValidationError) as exc_info: ProcessorResponse(api_response=api_response) errors = exc_info.value.errors() assert any(error['loc'] == ('detail',) for error in errors) def test_api_response_with_dict(self): """Test ProcessorResponse with dict apiResponse.""" api_response = { 'id': '123', 'status': 'success', 'timestamp': '2024-01-01T12:00:00Z', } detail = EventBridgeDetail( bucket={'name': 'test-bucket'}, object={'key': 'test/file.txt'} ) response = ProcessorResponse(detail=detail, apiResponse=api_response) assert response.apiResponse == api_response assert response.apiResponse['id'] == '123' def test_api_response_with_list(self): """Test ProcessorResponse with list apiResponse.""" detail = EventBridgeDetail( bucket={'name': 'test-bucket'}, object={'key': 'test/file.txt'} ) api_response = ['item1', 'item2', 'item3'] response = ProcessorResponse(detail=detail, apiResponse=api_response) assert response.apiResponse == api_response assert len(response.apiResponse) == 3 def test_api_response_with_string(self): """Test ProcessorResponse with string apiResponse.""" detail = EventBridgeDetail( bucket={'name': 'test-bucket'}, object={'key': 'test/file.txt'} ) api_response = 'Success message' response = ProcessorResponse(detail=detail, apiResponse=api_response) assert response.apiResponse == api_response def test_api_response_with_null(self): """Test ProcessorResponse with None apiResponse.""" detail = EventBridgeDetail( bucket={'name': 'test-bucket'}, object={'key': 'test/file.txt'} ) response = ProcessorResponse(detail=detail, apiResponse=None) assert response.apiResponse is None def test_api_response_with_number(self): """Test ProcessorResponse with numeric apiResponse.""" detail = EventBridgeDetail( bucket={'name': 'test-bucket'}, object={'key': 'test/file.txt'} ) response = ProcessorResponse(detail=detail, apiResponse=42) assert response.apiResponse == 42