|
1 | 1 | from functools import partial |
2 | | -from io import IOBase, BytesIO, SEEK_END |
| 2 | +from io import IOBase, BytesIO |
3 | 3 | from numbers import Number |
4 | 4 | import os |
5 | 5 | from unittest.mock import MagicMock, Mock, PropertyMock, call, patch, ANY |
@@ -264,16 +264,20 @@ def test_box_session_seeks_file_after_retry( |
264 | 264 | mock_file_2.tell.return_value = 3 |
265 | 265 | files = {'file': ('unused', mock_file_1), 'f2': ('unused', mock_file_2)} |
266 | 266 |
|
267 | | - box_response = box_session.post(url=test_url, files=files) |
| 267 | + # the multipart encoder sizes the streams itself, so only count the session's seeks |
| 268 | + with patch('boxsdk.session.session.MultipartStream'): |
| 269 | + box_response = box_session.post(url=test_url, files=files) |
268 | 270 | assert box_response.status_code == 200 |
269 | 271 | assert box_response.json() == generic_successful_response.json() |
270 | 272 | assert box_response.ok == generic_successful_response.ok |
271 | 273 | mock_file_1.tell.assert_called_with() |
272 | 274 | mock_file_2.tell.assert_called_with() |
273 | | - # before each attempt the session rewinds the stream, then the multipart |
274 | | - # encoder measures its size and restores the position |
275 | | - assert mock_file_1.seek.call_args_list == [call(0), call(0, SEEK_END), call(0)] * 2 |
276 | | - assert mock_file_2.seek.call_args_list == [call(3), call(0, SEEK_END), call(3)] * 2 |
| 275 | + mock_file_1.seek.assert_called_with(0) |
| 276 | + assert mock_file_1.seek.call_count == 2 |
| 277 | + mock_file_1.seek.assert_has_calls([call(0), call(0)]) |
| 278 | + mock_file_2.seek.assert_called_with(3) |
| 279 | + assert mock_file_2.seek.call_count == 2 |
| 280 | + mock_file_2.seek.assert_has_calls([call(3), call(3)]) |
277 | 281 |
|
278 | 282 |
|
279 | 283 | def test_box_session_raises_for_non_json_response( |
|
0 commit comments