|
| 1 | +"""Tests for model validation helper functions.""" |
| 2 | + |
| 3 | +from strands.models._validation import _has_s3_source |
| 4 | + |
| 5 | + |
| 6 | +class TestHasS3Source: |
| 7 | + """Tests for _has_s3_source helper function.""" |
| 8 | + |
| 9 | + def test_image_with_s3_source(self): |
| 10 | + """Test detection of S3 source in image content.""" |
| 11 | + content = {"image": {"source": {"s3Location": {"uri": "s3://bucket/key"}}}} |
| 12 | + assert _has_s3_source(content) is True |
| 13 | + |
| 14 | + def test_image_with_bytes_source(self): |
| 15 | + """Test that bytes source is not detected as S3.""" |
| 16 | + content = {"image": {"source": {"bytes": b"data"}}} |
| 17 | + assert _has_s3_source(content) is False |
| 18 | + |
| 19 | + def test_document_with_s3_source(self): |
| 20 | + """Test detection of S3 source in document content.""" |
| 21 | + content = {"document": {"source": {"s3Location": {"uri": "s3://bucket/key"}}}} |
| 22 | + assert _has_s3_source(content) is True |
| 23 | + |
| 24 | + def test_document_with_bytes_source(self): |
| 25 | + """Test that bytes source is not detected as S3.""" |
| 26 | + content = {"document": {"source": {"bytes": b"data"}}} |
| 27 | + assert _has_s3_source(content) is False |
| 28 | + |
| 29 | + def test_video_with_s3_source(self): |
| 30 | + """Test detection of S3 source in video content.""" |
| 31 | + content = {"video": {"source": {"s3Location": {"uri": "s3://bucket/key"}}}} |
| 32 | + assert _has_s3_source(content) is True |
| 33 | + |
| 34 | + def test_video_with_bytes_source(self): |
| 35 | + """Test that bytes source is not detected as S3.""" |
| 36 | + content = {"video": {"source": {"bytes": b"data"}}} |
| 37 | + assert _has_s3_source(content) is False |
| 38 | + |
| 39 | + def test_text_content(self): |
| 40 | + """Test that text content is not detected as S3 source.""" |
| 41 | + content = {"text": "hello"} |
| 42 | + assert _has_s3_source(content) is False |
| 43 | + |
| 44 | + def test_tool_use_content(self): |
| 45 | + """Test that toolUse content is not detected as S3 source.""" |
| 46 | + content = {"toolUse": {"name": "test", "input": {}, "toolUseId": "123"}} |
| 47 | + assert _has_s3_source(content) is False |
| 48 | + |
| 49 | + def test_tool_result_content(self): |
| 50 | + """Test that toolResult content is not detected as S3 source.""" |
| 51 | + content = {"toolResult": {"toolUseId": "123", "content": [{"text": "result"}]}} |
| 52 | + assert _has_s3_source(content) is False |
| 53 | + |
| 54 | + def test_image_without_source(self): |
| 55 | + """Test that image without source is not detected as S3.""" |
| 56 | + content = {"image": {"format": "png"}} |
| 57 | + assert _has_s3_source(content) is False |
| 58 | + |
| 59 | + def test_document_without_source(self): |
| 60 | + """Test that document without source is not detected as S3.""" |
| 61 | + content = {"document": {"format": "pdf", "name": "test.pdf"}} |
| 62 | + assert _has_s3_source(content) is False |
| 63 | + |
| 64 | + def test_video_without_source(self): |
| 65 | + """Test that video without source is not detected as S3.""" |
| 66 | + content = {"video": {"format": "mp4"}} |
| 67 | + assert _has_s3_source(content) is False |
0 commit comments