|
1 | 1 | """Tests for UploadLowLevelClient functionality.""" |
2 | 2 |
|
3 | 3 | from pathlib import Path |
| 4 | +from unittest.mock import patch |
| 5 | + |
| 6 | +import pytest |
4 | 7 |
|
5 | 8 | from sift_client._internal.low_level_wrappers.upload import UploadLowLevelClient |
6 | 9 |
|
7 | 10 |
|
8 | | -class TestUploadLowLevelClient: |
9 | | - class TestMimeAndContentTypeFromPath: |
10 | | - def test_parquet_file_extension(self): |
11 | | - _, mime, _ = UploadLowLevelClient._mime_and_content_type_from_path(Path("data.parquet")) |
12 | | - assert mime == "application/vnd.apache.parquet" |
| 11 | +class TestUploadAttachment: |
| 12 | + @pytest.mark.asyncio |
| 13 | + async def test_known_mime_type(self, tmp_path): |
| 14 | + test_file = tmp_path / "video.mp4" |
| 15 | + test_file.write_bytes(b"fake data") |
| 16 | + |
| 17 | + client = UploadLowLevelClient.__new__(UploadLowLevelClient) |
| 18 | + |
| 19 | + with patch.object(client, "_upload_file_sync", return_value="remote-file-123") as mock: |
| 20 | + await client.upload_attachment(path=test_file, entity_id="e1", entity_type="runs") |
| 21 | + |
| 22 | + _, _, mimetype, *_ = mock.call_args[0] |
| 23 | + assert mimetype == "video/mp4" |
| 24 | + |
| 25 | + @pytest.mark.asyncio |
| 26 | + async def test_unknown_extension_falls_back_to_application_x_ext(self, tmp_path): |
| 27 | + test_file = tmp_path / "data.pcapng" |
| 28 | + test_file.write_bytes(b"fake data") |
| 29 | + |
| 30 | + client = UploadLowLevelClient.__new__(UploadLowLevelClient) |
| 31 | + |
| 32 | + with patch.object(client, "_upload_file_sync", return_value="remote-file-123") as mock: |
| 33 | + await client.upload_attachment(path=test_file, entity_id="e1", entity_type="runs") |
| 34 | + |
| 35 | + _, _, mimetype, *_ = mock.call_args[0] |
| 36 | + assert mimetype == "application/x-pcapng" |
| 37 | + |
| 38 | + @pytest.mark.asyncio |
| 39 | + async def test_no_extension_falls_back_to_octet_stream(self, tmp_path): |
| 40 | + test_file = tmp_path / "README" |
| 41 | + test_file.write_bytes(b"fake data") |
| 42 | + |
| 43 | + client = UploadLowLevelClient.__new__(UploadLowLevelClient) |
| 44 | + |
| 45 | + with patch.object(client, "_upload_file_sync", return_value="remote-file-123") as mock: |
| 46 | + await client.upload_attachment(path=test_file, entity_id="e1", entity_type="runs") |
| 47 | + |
| 48 | + _, _, mimetype, *_ = mock.call_args[0] |
| 49 | + assert mimetype == "application/octet-stream" |
| 50 | + |
| 51 | + @pytest.mark.asyncio |
| 52 | + async def test_file_name_preserved(self, tmp_path): |
| 53 | + test_file = tmp_path / "my_file.pcapng" |
| 54 | + test_file.write_bytes(b"fake data") |
| 55 | + |
| 56 | + client = UploadLowLevelClient.__new__(UploadLowLevelClient) |
| 57 | + |
| 58 | + with patch.object(client, "_upload_file_sync", return_value="remote-file-123") as mock: |
| 59 | + await client.upload_attachment(path=test_file, entity_id="e1", entity_type="runs") |
13 | 60 |
|
14 | | - def test_pqt_file_extension(self): |
15 | | - _, mime, _ = UploadLowLevelClient._mime_and_content_type_from_path(Path("data.pqt")) |
16 | | - assert mime == "application/vnd.apache.parquet" |
| 61 | + file_name, *_ = mock.call_args[0] |
| 62 | + assert file_name == Path(test_file) |
0 commit comments