Skip to content

Commit 2a92e57

Browse files
committed
Update add_model_content unit tests
1 parent 856afef commit 2a92e57

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tests/unit/test_model_repository.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from unittest import mock
99

1010
import pytest
11+
from io import StringIO
12+
import json
1113
from sasctl import current_session
1214
from sasctl.services import model_repository as mr
1315

@@ -180,19 +182,28 @@ def test_add_model_content():
180182
with mock.patch('sasctl._services.model_repository.ModelRepository.get_model', return_value={'id': 123}):
181183
with mock.patch('sasctl._services.model_repository.ModelRepository.post') as post:
182184
text_data = 'Test text file contents'
185+
dict_data = {'Test': 'dict file contents'}
183186

184187
# Basic upload of text data
185188
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')}
187194

188-
# Upload of text data with content type
195+
# Upload of text data with content type (set content type after string detection and conversion)
189196
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+
192203
# Upload of binary data should include content type
193204
binary_data = 'Test binary file contents'.encode()
194205
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')}
196207

197208
# Should be able to customize content type
198209
mr.add_model_content(None, binary_data, 'test.pkl', content_type='application/image')

0 commit comments

Comments
 (0)