|
| 1 | +"""Tests for media type definitions.""" |
| 2 | + |
| 3 | +from strands.types.media import ( |
| 4 | + DocumentSource, |
| 5 | + ImageSource, |
| 6 | + S3Location, |
| 7 | + VideoSource, |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +class TestS3Location: |
| 12 | + """Tests for S3Location TypedDict.""" |
| 13 | + |
| 14 | + def test_s3_location_with_uri_only(self): |
| 15 | + """Test S3Location with only uri field.""" |
| 16 | + s3_loc: S3Location = {"uri": "s3://my-bucket/path/to/file.pdf"} |
| 17 | + |
| 18 | + assert s3_loc["uri"] == "s3://my-bucket/path/to/file.pdf" |
| 19 | + assert "bucketOwner" not in s3_loc |
| 20 | + |
| 21 | + def test_s3_location_with_bucket_owner(self): |
| 22 | + """Test S3Location with both uri and bucketOwner fields.""" |
| 23 | + s3_loc: S3Location = { |
| 24 | + "uri": "s3://my-bucket/path/to/file.pdf", |
| 25 | + "bucketOwner": "123456789012", |
| 26 | + } |
| 27 | + |
| 28 | + assert s3_loc["uri"] == "s3://my-bucket/path/to/file.pdf" |
| 29 | + assert s3_loc["bucketOwner"] == "123456789012" |
| 30 | + |
| 31 | + |
| 32 | +class TestDocumentSource: |
| 33 | + """Tests for DocumentSource TypedDict.""" |
| 34 | + |
| 35 | + def test_document_source_with_bytes(self): |
| 36 | + """Test DocumentSource with bytes content.""" |
| 37 | + doc_source: DocumentSource = {"bytes": b"document content"} |
| 38 | + |
| 39 | + assert doc_source["bytes"] == b"document content" |
| 40 | + assert "s3Location" not in doc_source |
| 41 | + |
| 42 | + def test_document_source_with_s3_location(self): |
| 43 | + """Test DocumentSource with s3Location.""" |
| 44 | + doc_source: DocumentSource = { |
| 45 | + "s3Location": { |
| 46 | + "uri": "s3://my-bucket/docs/report.pdf", |
| 47 | + "bucketOwner": "123456789012", |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + assert "bytes" not in doc_source |
| 52 | + assert doc_source["s3Location"]["uri"] == "s3://my-bucket/docs/report.pdf" |
| 53 | + assert doc_source["s3Location"]["bucketOwner"] == "123456789012" |
| 54 | + |
| 55 | + |
| 56 | +class TestImageSource: |
| 57 | + """Tests for ImageSource TypedDict.""" |
| 58 | + |
| 59 | + def test_image_source_with_bytes(self): |
| 60 | + """Test ImageSource with bytes content.""" |
| 61 | + img_source: ImageSource = {"bytes": b"image content"} |
| 62 | + |
| 63 | + assert img_source["bytes"] == b"image content" |
| 64 | + assert "s3Location" not in img_source |
| 65 | + |
| 66 | + def test_image_source_with_s3_location(self): |
| 67 | + """Test ImageSource with s3Location.""" |
| 68 | + img_source: ImageSource = { |
| 69 | + "s3Location": { |
| 70 | + "uri": "s3://my-bucket/images/photo.png", |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + assert "bytes" not in img_source |
| 75 | + assert img_source["s3Location"]["uri"] == "s3://my-bucket/images/photo.png" |
| 76 | + |
| 77 | + |
| 78 | +class TestVideoSource: |
| 79 | + """Tests for VideoSource TypedDict.""" |
| 80 | + |
| 81 | + def test_video_source_with_bytes(self): |
| 82 | + """Test VideoSource with bytes content.""" |
| 83 | + vid_source: VideoSource = {"bytes": b"video content"} |
| 84 | + |
| 85 | + assert vid_source["bytes"] == b"video content" |
| 86 | + assert "s3Location" not in vid_source |
| 87 | + |
| 88 | + def test_video_source_with_s3_location(self): |
| 89 | + """Test VideoSource with s3Location.""" |
| 90 | + vid_source: VideoSource = { |
| 91 | + "s3Location": { |
| 92 | + "uri": "s3://my-bucket/videos/clip.mp4", |
| 93 | + "bucketOwner": "987654321098", |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + assert "bytes" not in vid_source |
| 98 | + assert vid_source["s3Location"]["uri"] == "s3://my-bucket/videos/clip.mp4" |
| 99 | + assert vid_source["s3Location"]["bucketOwner"] == "987654321098" |
0 commit comments