Skip to content

Commit 0e74167

Browse files
committed
fix & test add_model_content()
1 parent 5cfdaff commit 0e74167

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/sasctl/_services/model_repository.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def add_model_content(cls, model, file, name, role=None, content_type=None):
403403
if content_type is not None:
404404
files = {name: (name, file, content_type)}
405405
else:
406-
files = {name: file.read()}
406+
files = {name: file}
407407

408408
metadata = {'role': role, 'name': name}
409409

tests/unit/test_model_repository.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,27 @@ def test_get_model_by_name():
173173
result = mr.get_model(MODEL_NAME)
174174
assert result['id'] == 12345
175175
assert result['name'] == MODEL_NAME
176+
177+
178+
def test_add_model_content():
179+
180+
with mock.patch('sasctl._services.model_repository.ModelRepository.get_model', return_value={'id': 123}):
181+
with mock.patch('sasctl._services.model_repository.ModelRepository.post') as post:
182+
text_data = 'Test text file contents'
183+
184+
# Basic upload of text data
185+
mr.add_model_content(None, text_data, 'test.txt')
186+
assert post.call_args[1]['files'] == {'test.txt': text_data}
187+
188+
# Upload of text data with content type
189+
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+
192+
# Upload of binary data should include content type
193+
binary_data = 'Test binary file contents'.encode()
194+
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')}
196+
197+
# Should be able to customize content type
198+
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')}

0 commit comments

Comments
 (0)