Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_metadata.py
Show All 32 Lines | ): | ||||
""" | """ | ||||
invalid_swhid = "swh:1:dir :31b5c8cc985d190b5a7ef4878128ebfdc2358f49" | invalid_swhid = "swh:1:dir :31b5c8cc985d190b5a7ef4878128ebfdc2358f49" | ||||
xml_data = atom_dataset["entry-data-with-swhid"].format(swhid=invalid_swhid) | xml_data = atom_dataset["entry-data-with-swhid"].format(swhid=invalid_swhid) | ||||
response = authenticated_client.post( | response = authenticated_client.post( | ||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
content_type="application/atom+xml;type=entry", | content_type="application/atom+xml;type=entry", | ||||
data=xml_data, | data=xml_data, | ||||
HTTP_SLUG="external-id", | |||||
) | ) | ||||
assert response.status_code == status.HTTP_400_BAD_REQUEST | assert response.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert b"Invalid SWHID reference" in response.content | assert b"Invalid SWHID reference" in response.content | ||||
def test_deposit_metadata_fails_functional_checks( | def test_deposit_metadata_fails_functional_checks( | ||||
authenticated_client, deposit_collection, atom_dataset | authenticated_client, deposit_collection, atom_dataset | ||||
): | ): | ||||
"""Posting functionally invalid metadata swhid is bad request returned to client | """Posting functionally invalid metadata swhid is bad request returned to client | ||||
""" | """ | ||||
swhid = "swh:1:dir:31b5c8cc985d190b5a7ef4878128ebfdc2358f49" | swhid = "swh:1:dir:31b5c8cc985d190b5a7ef4878128ebfdc2358f49" | ||||
invalid_xml_data = atom_dataset[ | invalid_xml_data = atom_dataset[ | ||||
"entry-data-with-swhid-fail-metadata-functional-checks" | "entry-data-with-swhid-fail-metadata-functional-checks" | ||||
].format(swhid=swhid) | ].format(swhid=swhid) | ||||
response = authenticated_client.post( | response = authenticated_client.post( | ||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
content_type="application/atom+xml;type=entry", | content_type="application/atom+xml;type=entry", | ||||
data=invalid_xml_data, | data=invalid_xml_data, | ||||
HTTP_SLUG="external-id", | |||||
) | ) | ||||
assert response.status_code == status.HTTP_400_BAD_REQUEST | assert response.status_code == status.HTTP_400_BAD_REQUEST | ||||
assert b"Functional metadata checks failure" in response.content | assert b"Functional metadata checks failure" in response.content | ||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"swhid,target_type", | "swhid,target_type", | ||||
[ | [ | ||||
▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | ): | ||||
xml_data = atom_dataset["entry-data-with-swhid"].format(swhid=swhid) | xml_data = atom_dataset["entry-data-with-swhid"].format(swhid=swhid) | ||||
deposit_client = authenticated_client.deposit_client | deposit_client = authenticated_client.deposit_client | ||||
response = authenticated_client.post( | response = authenticated_client.post( | ||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
content_type="application/atom+xml;type=entry", | content_type="application/atom+xml;type=entry", | ||||
data=xml_data, | data=xml_data, | ||||
HTTP_SLUG="external-id", | |||||
) | ) | ||||
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)) | ||||
# Ensure the deposit is finalized | # Ensure the deposit is finalized | ||||
deposit_id = int(response_content["deposit_id"]) | deposit_id = int(response_content["deposit_id"]) | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | ): | ||||
""" | """ | ||||
xml_data = atom_dataset["entry-data-with-origin"].format(url=url) | xml_data = atom_dataset["entry-data-with-origin"].format(url=url) | ||||
deposit_client = authenticated_client.deposit_client | deposit_client = authenticated_client.deposit_client | ||||
response = authenticated_client.post( | response = authenticated_client.post( | ||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
content_type="application/atom+xml;type=entry", | content_type="application/atom+xml;type=entry", | ||||
data=xml_data, | data=xml_data, | ||||
HTTP_SLUG="external-id", | |||||
) | ) | ||||
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)) | ||||
# Ensure the deposit is finalized | # Ensure the deposit is finalized | ||||
deposit_id = int(response_content["deposit_id"]) | deposit_id = int(response_content["deposit_id"]) | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
# we got not swhid as input so we cannot have those | # we got not swhid as input so we cannot have those | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |