|
1 | | -import io |
2 | | - |
3 | | -import httpx |
4 | 1 | import pytest |
5 | | -import respx |
6 | 2 |
|
7 | 3 | from mpt_api_client.resources.notifications.batches import ( |
8 | 4 | AsyncBatchesService, |
@@ -32,97 +28,3 @@ def test_async_batches_service_methods(async_batches_service, method): |
32 | 28 | result = hasattr(async_batches_service, method) |
33 | 29 |
|
34 | 30 | assert result is True |
35 | | - |
36 | | - |
37 | | -def test_sync_get_batch_attachment(batches_service): |
38 | | - attachment_content = b"Attachment file content or binary data" |
39 | | - with respx.mock: |
40 | | - mock_route = respx.get( |
41 | | - "https://api.example.com/public/v1/notifications/batches/BAT-123/attachments/ATT-456" |
42 | | - ).mock( |
43 | | - return_value=httpx.Response( |
44 | | - status_code=httpx.codes.OK, |
45 | | - headers={ |
46 | | - "content-type": "application/octet-stream", |
47 | | - "content-disposition": ( |
48 | | - 'form-data; name="file"; filename="batch_attachment.pdf"' |
49 | | - ), |
50 | | - }, |
51 | | - content=attachment_content, |
52 | | - ) |
53 | | - ) |
54 | | - |
55 | | - result = batches_service.get_batch_attachment("BAT-123", "ATT-456") |
56 | | - |
57 | | - assert mock_route.call_count == 1 |
58 | | - assert result.file_contents == attachment_content |
59 | | - assert result.content_type == "application/octet-stream" |
60 | | - assert result.filename == "batch_attachment.pdf" |
61 | | - |
62 | | - |
63 | | -@pytest.mark.asyncio |
64 | | -async def test_async_get_batch_attachment(async_batches_service): |
65 | | - attachment_content = b"Attachment file content or binary data" |
66 | | - with respx.mock: |
67 | | - mock_route = respx.get( |
68 | | - "https://api.example.com/public/v1/notifications/batches/BAT-123/attachments/ATT-456" |
69 | | - ).mock( |
70 | | - return_value=httpx.Response( |
71 | | - status_code=httpx.codes.OK, |
72 | | - headers={ |
73 | | - "content-type": "application/octet-stream", |
74 | | - "content-disposition": ( |
75 | | - 'form-data; name="file"; filename="batch_attachment.pdf"' |
76 | | - ), |
77 | | - }, |
78 | | - content=attachment_content, |
79 | | - ) |
80 | | - ) |
81 | | - |
82 | | - result = await async_batches_service.get_batch_attachment("BAT-123", "ATT-456") |
83 | | - |
84 | | - assert mock_route.call_count == 1 |
85 | | - assert result.file_contents == attachment_content |
86 | | - assert result.content_type == "application/octet-stream" |
87 | | - assert result.filename == "batch_attachment.pdf" |
88 | | - |
89 | | - |
90 | | -def test_sync_batches_create_with_data(batches_service): |
91 | | - batch_data = {"name": "Test Batch"} |
92 | | - with respx.mock: |
93 | | - mock_route = respx.post("https://api.example.com/public/v1/notifications/batches").mock( |
94 | | - return_value=httpx.Response( |
95 | | - status_code=httpx.codes.OK, |
96 | | - json={"id": "BAT-133", "name": "Test Batch"}, |
97 | | - ) |
98 | | - ) |
99 | | - files = {"attachment": ("test.pdf", io.BytesIO(b"PDF content"), "application/pdf")} |
100 | | - |
101 | | - result = batches_service.create(batch_data, files=files) |
102 | | - |
103 | | - request = mock_route.calls[0].request |
104 | | - assert b'Content-Disposition: form-data; name="_attachment_data"' in request.content |
105 | | - assert mock_route.call_count == 1 |
106 | | - assert result.id == "BAT-133" |
107 | | - assert result.name == "Test Batch" |
108 | | - |
109 | | - |
110 | | -@pytest.mark.asyncio |
111 | | -async def test_async_batches_create_with_data(async_batches_service): |
112 | | - batch_data = {"name": "Test Batch"} |
113 | | - with respx.mock: |
114 | | - mock_route = respx.post("https://api.example.com/public/v1/notifications/batches").mock( |
115 | | - return_value=httpx.Response( |
116 | | - status_code=httpx.codes.OK, |
117 | | - json={"id": "BAT-133", "name": "Test Batch"}, |
118 | | - ) |
119 | | - ) |
120 | | - files = {"attachment": ("test.pdf", io.BytesIO(b"PDF content"), "application/pdf")} |
121 | | - |
122 | | - result = await async_batches_service.create(batch_data, files=files) |
123 | | - |
124 | | - request = mock_route.calls[0].request |
125 | | - assert b'Content-Disposition: form-data; name="_attachment_data"' in request.content |
126 | | - assert mock_route.call_count == 1 |
127 | | - assert result.id == "BAT-133" |
128 | | - assert result.name == "Test Batch" |
0 commit comments