|
| 1 | +"""Tests for DocumentStore""" |
| 2 | +import pytest |
| 3 | +from unittest.mock import Mock |
| 4 | +from src.document_store import DocumentStore, IntermediaryBodyStoreError |
| 5 | + |
| 6 | + |
| 7 | +class TestDocumentStore: |
| 8 | + """Test suite for DocumentStore""" |
| 9 | + |
| 10 | + def test_store_document_success(self): |
| 11 | + """Successfully stores document and returns S3 key""" |
| 12 | + mock_s3_client = Mock() |
| 13 | + mock_s3_client.put_object.return_value = { |
| 14 | + 'ResponseMetadata': {'HTTPStatusCode': 200} |
| 15 | + } |
| 16 | + |
| 17 | + config = Mock() |
| 18 | + config.s3_client = mock_s3_client |
| 19 | + config.transactional_data_bucket = 'test-pii-bucket' |
| 20 | + |
| 21 | + store = DocumentStore(config) |
| 22 | + |
| 23 | + result = store.store_document( |
| 24 | + sender_id='SENDER_001', |
| 25 | + message_reference='ref_123', |
| 26 | + content=b'test content' |
| 27 | + ) |
| 28 | + |
| 29 | + assert result == 'document-reference/SENDER_001_ref_123' |
| 30 | + mock_s3_client.put_object.assert_called_once_with( |
| 31 | + Bucket='test-pii-bucket', |
| 32 | + Key='document-reference/SENDER_001_ref_123', |
| 33 | + Body=b'test content' |
| 34 | + ) |
| 35 | + |
| 36 | + def test_store_document_s3_failure_raises_error(self): |
| 37 | + """Raises IntermediaryBodyStoreError when S3 put_object fails""" |
| 38 | + mock_s3_client = Mock() |
| 39 | + mock_s3_client.put_object.return_value = { |
| 40 | + 'ResponseMetadata': {'HTTPStatusCode': 500} |
| 41 | + } |
| 42 | + |
| 43 | + config = Mock() |
| 44 | + config.s3_client = mock_s3_client |
| 45 | + config.transactional_data_bucket = 'test-pii-bucket' |
| 46 | + |
| 47 | + store = DocumentStore(config) |
| 48 | + |
| 49 | + with pytest.raises(IntermediaryBodyStoreError): |
| 50 | + store.store_document( |
| 51 | + sender_id='SENDER_001', |
| 52 | + message_reference='ref_123', |
| 53 | + content=b'test content' |
| 54 | + ) |
0 commit comments