|
8 | 8 | from unittest import mock
|
9 | 9 |
|
10 | 10 | import pytest
|
| 11 | +from io import StringIO |
| 12 | +import json |
11 | 13 | from sasctl import current_session
|
12 | 14 | from sasctl.services import model_repository as mr
|
13 | 15 |
|
@@ -180,19 +182,28 @@ def test_add_model_content():
|
180 | 182 | with mock.patch('sasctl._services.model_repository.ModelRepository.get_model', return_value={'id': 123}):
|
181 | 183 | with mock.patch('sasctl._services.model_repository.ModelRepository.post') as post:
|
182 | 184 | text_data = 'Test text file contents'
|
| 185 | + dict_data = {'Test': 'dict file contents'} |
183 | 186 |
|
184 | 187 | # Basic upload of text data
|
185 | 188 | mr.add_model_content(None, text_data, 'test.txt')
|
186 |
| - assert post.call_args[1]['files'] == {'test.txt': text_data} |
| 189 | + assert post.call_args[1]['files'] == {'files': ('test.txt', StringIO(text_data), 'multipart/form-data')} |
| 190 | + |
| 191 | + # Basic upload of dict data |
| 192 | + mr.add_model_content(None, dict_data, 'dict.json') |
| 193 | + assert post.call_args[1]['files'] == {'files': ('dict.json', StringIO(json.dumps(dict_data)), 'multipart/form-data')} |
187 | 194 |
|
188 |
| - # Upload of text data with content type |
| 195 | + # Upload of text data with content type (set content type after string detection and conversion) |
189 | 196 | mr.add_model_content(None, text_data, 'test.txt', content_type='application/text')
|
190 |
| - assert post.call_args[1]['files'] == {'test.txt': ('test.txt', text_data, 'application/text')} |
191 |
| - |
| 197 | + assert post.call_args[1]['files'] == {'files': ('test.txt', StringIO(text_data), 'multipart/form-data')} |
| 198 | + |
| 199 | + # Upload of dict data with content type (set content type after dict detection and conversion) |
| 200 | + mr.add_model_content(None, dict_data, 'dict.json', content_type='application/json') |
| 201 | + assert post.call_args[1]['files'] == {'files': ('dict.json', StringIO(json.dumps(dict_data)), 'multipart/form-data')} |
| 202 | + |
192 | 203 | # Upload of binary data should include content type
|
193 | 204 | binary_data = 'Test binary file contents'.encode()
|
194 | 205 | mr.add_model_content(None, binary_data, 'test.pkl')
|
195 |
| - assert post.call_args[1]['files'] == {'test.pkl': ('test.pkl', binary_data, 'application/octet-stream')} |
| 206 | + assert post.call_args[1]['files'] == {'test.pkl': ('test.pkl', binary_data, 'multipart/form-data')} |
196 | 207 |
|
197 | 208 | # Should be able to customize content type
|
198 | 209 | mr.add_model_content(None, binary_data, 'test.pkl', content_type='application/image')
|
|
0 commit comments