@@ -173,3 +173,27 @@ def test_get_model_by_name():
173
173
result = mr .get_model (MODEL_NAME )
174
174
assert result ['id' ] == 12345
175
175
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