Skip to content

Commit 5f230a3

Browse files
committed
Fix unit test failure wrt StringIO objects
1 parent de24dea commit 5f230a3

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

tests/unit/test_model_repository.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,25 +186,37 @@ def test_add_model_content():
186186

187187
# Basic upload of text data
188188
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+
191194
# Basic upload of dict data
192195
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'
194200

195201
# Upload of text data with content type (set content type after string detection and conversion)
196202
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+
199208
# Upload of dict data with content type (set content type after dict detection and conversion)
200209
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+
203215
# Upload of binary data should include content type
204216
binary_data = 'Test binary file contents'.encode()
205217
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')}
207219

208220
# Should be able to customize content type
209221
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

Comments
 (0)