def test_put_badstream(client, db, bucket, multipart, multipart_url, get_json, admin_user): """Test uploading to a completed multipart upload.""" login_user(client, admin_user) client.put( multipart_url + '&partNumber={0}'.format(1), input_stream=BytesIO(b'a' * multipart.chunk_size), ) # Part exists data = get_json(client.get(multipart_url), code=200) assert len(data['parts']) == 1 pytest.raises( ValueError, client.put, multipart_url + '&partNumber={0}'.format(1), input_stream=BadBytesIO(b'b' * multipart.chunk_size), ) # Part was removed due to faulty upload which might have written partial # content to the file. data = get_json(client.get(multipart_url), code=200) assert len(data['parts']) == 0
def test_put_error(client, bucket): """Test upload - cancelled by user.""" object_url = url_for('invenio_files_rest.object_api', bucket_id=bucket.id, key='test.txt') pytest.raises(ValueError, client.put, object_url, input_stream=BadBytesIO(b'a' * 128)) assert FileInstance.query.count() == 0 assert ObjectVersion.query.count() == 0 # Ensure that the file was removed. assert len(list(opener.opendir(bucket.location.uri).walk('.'))) == 3