Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_collection_post_atom.py
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | response = authenticated_client.post( | ||||
content_type="application/atom+xml;type=entry", | content_type="application/atom+xml;type=entry", | ||||
data=atom_dataset["entry-data-parsing-error-prone"], | data=atom_dataset["entry-data-parsing-error-prone"], | ||||
HTTP_SLUG="external-id", | HTTP_SLUG="external-id", | ||||
) | ) | ||||
assert response.status_code == status.HTTP_400_BAD_REQUEST | assert response.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert b"Malformed xml metadata" in response.content | assert b"Malformed xml metadata" in response.content | ||||
def test_post_deposit_atom_403_wrong_origin_url_prefix( | |||||
authenticated_client, deposit_collection, atom_dataset, deposit_user | |||||
): | |||||
"""Creating an origin for a prefix not owned by the client is forbidden | |||||
""" | |||||
origin_url = "http://example.org/foo" | |||||
response = authenticated_client.post( | |||||
reverse(COL_IRI, args=[deposit_collection.name]), | |||||
content_type="application/atom+xml;type=entry", | |||||
data=atom_dataset["entry-data0"] % origin_url, | |||||
HTTP_IN_PROGRESS="true", | |||||
) | |||||
assert response.status_code == status.HTTP_403_FORBIDDEN | |||||
expected_msg = ( | |||||
f"Cannot create origin {origin_url}, " | |||||
f"it must start with {deposit_user.provider_url}" | |||||
) | |||||
assert expected_msg in response.content.decode() | |||||
def test_post_deposit_atom_use_slug_header( | def test_post_deposit_atom_use_slug_header( | ||||
authenticated_client, deposit_collection, deposit_user, atom_dataset, mocker | authenticated_client, deposit_collection, deposit_user, atom_dataset, mocker | ||||
): | ): | ||||
"""Posting an atom entry with a slug header but no origin url generates | """Posting an atom entry with a slug header but no origin url generates | ||||
an origin url from the slug | an origin url from the slug | ||||
""" | """ | ||||
url = reverse(COL_IRI, args=[deposit_collection.name]) | url = reverse(COL_IRI, args=[deposit_collection.name]) | ||||
slug = str(uuid.uuid4()) | slug = str(uuid.uuid4()) | ||||
# when | # when | ||||
response = authenticated_client.post( | response = authenticated_client.post( | ||||
url, | url, | ||||
content_type="application/atom+xml;type=entry", | content_type="application/atom+xml;type=entry", | ||||
data=atom_dataset["entry-data-no-origin-url"], | data=atom_dataset["entry-data-no-origin-url"], | ||||
HTTP_IN_PROGRESS="false", | HTTP_IN_PROGRESS="false", | ||||
HTTP_SLUG=slug, | HTTP_SLUG=slug, | ||||
ardumont: some recent discussion about testing the full error message being not DRY occur recently.
So… | |||||
Done Inline ActionsNo, that would not be a good test, because the error could be "Cannot create origin because example.org is reserved". I could test both "Cannot create origin" and "it must start with" are in the error, but that's barely different from my test... vlorentz: No, that would not be a good test, because the error could be "Cannot create origin because… | |||||
) | ) | ||||
assert response.status_code == status.HTTP_201_CREATED | assert response.status_code == status.HTTP_201_CREATED | ||||
response_content = parse_xml(BytesIO(response.content)) | response_content = parse_xml(BytesIO(response.content)) | ||||
deposit_id = response_content["swh:deposit_id"] | deposit_id = response_content["swh:deposit_id"] | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
assert deposit.collection == deposit_collection | assert deposit.collection == deposit_collection | ||||
▲ Show 20 Lines • Show All 290 Lines • Show Last 20 Lines |
some recent discussion about testing the full error message being not DRY occur recently.
So, in that regards, the following assertion should be enough: