Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_collection_post_binary.py
Show First 20 Lines • Show All 262 Lines • ▼ Show 20 Lines | ): | ||||
# then | # then | ||||
assert response.status_code == status.HTTP_413_REQUEST_ENTITY_TOO_LARGE | assert response.status_code == status.HTTP_413_REQUEST_ENTITY_TOO_LARGE | ||||
assert b"Upload size limit exceeded" in response.content | assert b"Upload size limit exceeded" in response.content | ||||
with pytest.raises(Deposit.DoesNotExist): | with pytest.raises(Deposit.DoesNotExist): | ||||
Deposit.objects.get(external_id=external_id) | Deposit.objects.get(external_id=external_id) | ||||
def test_post_deposit_binary_upload_fail_if_content_length_missing( | |||||
authenticated_client, deposit_collection, sample_archive, tmp_path | |||||
): | |||||
"""The Content-Length header is mandatory | |||||
""" | |||||
tmp_path = str(tmp_path) | |||||
url = reverse(COL_IRI, args=[deposit_collection.name]) | |||||
archive = create_arborescence_archive( | |||||
tmp_path, "archive2", "file2", b"some content in file", up_to_size=500 | |||||
) | |||||
external_id = "some-external-id" | |||||
# when | |||||
response = authenticated_client.post( | |||||
url, | |||||
content_type="application/zip", | |||||
data=archive["data"], | |||||
# + headers | |||||
CONTENT_LENGTH=None, | |||||
HTTP_SLUG=external_id, | |||||
HTTP_CONTENT_MD5=archive["md5sum"], | |||||
HTTP_PACKAGING="http://purl.org/net/sword/package/SimpleZip", | |||||
HTTP_IN_PROGRESS="false", | |||||
HTTP_CONTENT_DISPOSITION="attachment; filename=filename0", | |||||
) | |||||
# then | |||||
assert response.status_code == status.HTTP_400_BAD_REQUEST | |||||
assert b"the CONTENT_LENGTH header must be sent." in response.content | |||||
with pytest.raises(Deposit.DoesNotExist): | |||||
Deposit.objects.get(external_id=external_id) | |||||
def test_post_deposit_2_post_2_different_deposits( | def test_post_deposit_2_post_2_different_deposits( | ||||
authenticated_client, deposit_collection, sample_archive | authenticated_client, deposit_collection, sample_archive | ||||
): | ): | ||||
"""2 posting deposits should return 2 different 201 with receipt | """2 posting deposits should return 2 different 201 with receipt | ||||
""" | """ | ||||
url = reverse(COL_IRI, args=[deposit_collection.name]) | url = reverse(COL_IRI, args=[deposit_collection.name]) | ||||
▲ Show 20 Lines • Show All 300 Lines • Show Last 20 Lines |