def test_string_path_saving(tmpdir): destination = tmpdir.join('test.txt') path = str(destination) filehandle = FileStorage(stream=BytesIO(b'hello world')) transfer._use_filehandle_to_save(path)(filehandle) assert destination.read(mode='rb') == b'hello world'
def test_writeable_saving(): destination = BytesIO() filehandle = FileStorage(stream=BytesIO(b'hello world')) transfer._use_filehandle_to_save(destination)(filehandle) destination.seek(0) assert destination.read() == b'hello world'
def test_string_path_saving(): source = BytesIO() filehandle = FileStorage(stream=source, filename='test.png') dummy_save = transfer._use_filehandle_to_save('test.png') with mock.patch('werkzeug.FileStorage.save') as mocked_save: dummy_save(filehandle, {'buffer_size': None}) assert mocked_save.call_args == mock.call('test.png', None)
def test_writeable_saving(): destination = BytesIO() filehandle = FileStorage(stream=BytesIO(b'hello world')) dummy_save = transfer._use_filehandle_to_save(destination) with mock.patch('werkzeug.FileStorage.save') as mocked_save: dummy_save(filehandle, {'buffer_size': 1}) assert mocked_save.call_count == 1 assert mocked_save.call_args == mock.call(destination, 1)