Example #1
0
def test_upload_chunks__errors():
    """It should try up to three additional times to upload each chunk."""

    bucket = mock.Mock()
    mp_upload = mock.Mock()
    mp_upload.id = 1234
    mp_upload.upload_part_from_file = mock.Mock(side_effect=IOError)
    bucket.get_all_multipart_uploads = mock.Mock(return_value=[mp_upload])

    with mock.patch.object(upload, "FileChunkIO"):
        with pytest.raises(IOError):
            upload._upload_chunk(bucket, 1234, 1, "some-fake-file", 0, 50)

    assert bucket.get_all_multipart_uploads.call_count == 4
Example #2
0
def test_upload_chunk(capfd):
    """Ensure the chunk uploader is working as expected."""

    bucket = mock.Mock()
    mp_upload = mock.Mock()
    mp_upload.id = 1234
    bucket.get_all_multipart_uploads = mock.Mock(return_value=[mp_upload])

    with mock.patch.object(upload, "FileChunkIO") as patched_filechunkio:
        upload._upload_chunk(bucket, 1234, 1, "some-fake-file", 0, 50)

    patched_filechunkio.assert_called_once_with("some-fake-file", "rb", offset=0, bytes=50)

    mp_upload.upload_part_from_file.assert_called_once_with(
        fp=patched_filechunkio().__enter__(), part_num=1, cb=upload.print_dot
    )

    out, err = capfd.readouterr()
    assert not err
    assert "1" in out