authenticated_client = <rest_framework.test.APIClient object at 0x7fdb8c85e400>
deposit_collection = <DepositCollection: {'id': 20, 'name': 'test'}>
sample_archive = {'data': b'PK\x03\x04\x14\x00\x00\x00\x00\x001\\\xbcP\xcba\xb4c\x14\x00\x00\x00\x14\x00\x00\x00\x05\x00\x00\x00file1so...ytest-0/test_post_deposit_binary_uploa0/tmp02swy3fg', 'length': 128, 'md5sum': 'db665c2afdbb00059fd0a1dcbcc67594', ...}
def test_post_deposit_binary_upload_ok(
authenticated_client, deposit_collection, sample_archive
):
"""Binary upload with correct headers should return 201 with receipt
"""
# given
url = reverse(COL_IRI, args=[deposit_collection.name])
external_id = "some-external-id-1"
# when
response = authenticated_client.post(
url,
content_type="application/zip", # as zip
data=sample_archive["data"],
# + headers
CONTENT_LENGTH=sample_archive["length"],
# other headers needs HTTP_ prefix to be taken into account
HTTP_SLUG=external_id,
HTTP_CONTENT_MD5=sample_archive["md5sum"],
HTTP_PACKAGING="http://purl.org/net/sword/package/SimpleZip",
HTTP_IN_PROGRESS="false",
HTTP_CONTENT_DISPOSITION="attachment; filename=%s" % (sample_archive["name"],),
)
# then
response_content = parse_xml(BytesIO(response.content))
assert response.status_code == status.HTTP_201_CREATED
deposit_id = response_content["deposit_id"]
deposit = Deposit.objects.get(pk=deposit_id)
assert deposit.status == DEPOSIT_STATUS_DEPOSITED
assert deposit.external_id == external_id
assert deposit.collection == deposit_collection
assert deposit.swh_id is None
deposit_request = DepositRequest.objects.get(deposit=deposit)
> check_archive(sample_archive["name"], deposit_request.archive.name)
.tox/py3/lib/python3.7/site-packages/swh/deposit/tests/api/test_deposit_binary.py:119:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
archive_name = 'archive1.zip', archive_name_to_check = 'client_19/archive1.zip'
def check_archive(archive_name: str, archive_name_to_check: str):
"""Helper function to ensure archive_name is present within the
archive_name_to_check.
Raises:
AssertionError if archive_name is not present within
archive_name_to_check
"""
pattern = re.compile(".*/.*_%s" % archive_name)
> assert pattern.match(archive_name_to_check) is not None
E AssertionError: assert None is not None
E + where None = <built-in method match of re.Pattern object at 0x7fdb8ca3b490>('client_19/archive1.zip')
E + where <built-in method match of re.Pattern object at 0x7fdb8ca3b490> = re.compile('.*/.*_archive1.zip').match
.tox/py3/lib/python3.7/site-packages/swh/deposit/tests/common.py:137: AssertionError
TEST RESULT
TEST RESULT
- Run At
- May 28 2020, 1:34 PM