@@ -186,25 +186,37 @@ def test_add_model_content():
186
186
187
187
# Basic upload of text data
188
188
mr .add_model_content (None , text_data , 'test.txt' )
189
- assert post .call_args [1 ]['files' ] == {'files' : ('test.txt' , StringIO (text_data ), 'multipart/form-data' )}
190
-
189
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][0 ] == 'files'
190
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][1 ][0 ] == 'test.txt'
191
+ assert (list (post .call_args [1 ]['files' ].items ())[0 ][1 ][1 ]).read () == StringIO (text_data ).read ()
192
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][1 ][2 ] == 'multipart/form-data'
193
+
191
194
# Basic upload of dict data
192
195
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' )}
196
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][0 ] == 'files'
197
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][1 ][0 ] == 'dict.json'
198
+ assert (list (post .call_args [1 ]['files' ].items ())[0 ][1 ][1 ]).read () == StringIO (json .dumps (dict_data )).read ()
199
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][1 ][2 ] == 'multipart/form-data'
194
200
195
201
# Upload of text data with content type (set content type after string detection and conversion)
196
202
mr .add_model_content (None , text_data , 'test.txt' , content_type = 'application/text' )
197
- assert post .call_args [1 ]['files' ] == {'files' : ('test.txt' , StringIO (text_data ), 'multipart/form-data' )}
198
-
203
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][0 ] == 'files'
204
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][1 ][0 ] == 'test.txt'
205
+ assert (list (post .call_args [1 ]['files' ].items ())[0 ][1 ][1 ]).read () == StringIO (text_data ).read ()
206
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][1 ][2 ] == 'multipart/form-data'
207
+
199
208
# Upload of dict data with content type (set content type after dict detection and conversion)
200
209
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
-
210
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][0 ] == 'files'
211
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][1 ][0 ] == 'dict.json'
212
+ assert (list (post .call_args [1 ]['files' ].items ())[0 ][1 ][1 ]).read () == StringIO (json .dumps (dict_data )).read ()
213
+ assert list (post .call_args [1 ]['files' ].items ())[0 ][1 ][2 ] == 'multipart/form-data'
214
+
203
215
# Upload of binary data should include content type
204
216
binary_data = 'Test binary file contents' .encode ()
205
217
mr .add_model_content (None , binary_data , 'test.pkl' )
206
- assert post .call_args [1 ]['files' ] == {'test.pkl ' : ('test.pkl' , binary_data , 'multipart/form-data' )}
218
+ assert post .call_args [1 ]['files' ] == {'files ' : ('test.pkl' , binary_data , 'multipart/form-data' )}
207
219
208
220
# Should be able to customize content type
209
221
mr .add_model_content (None , binary_data , 'test.pkl' , content_type = 'application/image' )
210
- assert post .call_args [1 ]['files' ] == {'test.pkl ' : ('test.pkl' , binary_data , 'application/image' )}
222
+ assert post .call_args [1 ]['files' ] == {'files ' : ('test.pkl' , binary_data , 'application/image' )}
0 commit comments