Skip to content

Commit a45fba3

Browse files
committed
Adjust add_model_content unit tests
1 parent 727c5de commit a45fba3

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/sasctl/_services/model_repository.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,9 @@ def create_model(
366366
)
367367

368368
@classmethod
369-
def add_model_content(cls, model, file, name, role=None, content_type=None):
369+
def add_model_content(
370+
cls, model, file, name, role=None, content_type="multipart/form-data"
371+
):
370372
"""Add additional files to the model.
371373
372374
Parameters
@@ -379,9 +381,9 @@ def add_model_content(cls, model, file, name, role=None, content_type=None):
379381
name : str
380382
Name of the file related to the model.
381383
role : str
382-
Role of the model file, such as 'Python pickle'.
384+
Role of the model file, such as 'Python pickle'. Default value is None.
383385
content_type : str
384-
an HTTP Content-Type value
386+
An HTTP Content-Type value. Default value is multipart/form-data.
385387
386388
Returns
387389
-------
@@ -397,7 +399,7 @@ def add_model_content(cls, model, file, name, role=None, content_type=None):
397399
model = cls.get_model(model)
398400
id_ = model["id"]
399401

400-
if content_type is None and isinstance(file, bytes):
402+
if content_type is "multipart/form-data" and isinstance(file, bytes):
401403
content_type = "application/octet-stream"
402404
elif isinstance(file, dict):
403405
import json

tests/unit/test_model_repository.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,23 @@ def test_add_model_content():
183183

184184
# Basic upload of text data
185185
mr.add_model_content(None, text_data, 'test.txt')
186-
assert post.call_args[1]['files'] == {'test.txt': text_data}
186+
assert post.call_args[1]['files'] == {'files': ('test.txt', text_data, 'multipart/form-data')}
187187

188188
# Upload of text data with content type
189189
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')}
190+
assert post.call_args[1]['files'] == {'files': ('test.txt', text_data, 'application/text')}
191+
192+
# Upload of dict data without content type
193+
import json
194+
dict_data = {'data': text_data}
195+
mr.add_model_content(None, dict_data, 'dict.json')
196+
assert post.call_args[1]['files'] == {'files': ('dict.json', json.dumps(dict_data), 'multipart/form-data')}
191197

192198
# Upload of binary data should include content type
193199
binary_data = 'Test binary file contents'.encode()
194200
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')}
201+
assert post.call_args[1]['files'] == {'files': ('test.pkl', binary_data, 'application/octet-stream')}
196202

197203
# Should be able to customize content type
198204
mr.add_model_content(None, binary_data, 'test.pkl', content_type='application/image')
199-
assert post.call_args[1]['files'] == {'test.pkl': ('test.pkl', binary_data, 'application/image')}
205+
assert post.call_args[1]['files'] == {'files': ('test.pkl', binary_data, 'application/image')}

0 commit comments

Comments
 (0)