Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_collection_reuse_slug.py
Show All 11 Lines | from swh.deposit.config import ( | ||||
COL_IRI, | COL_IRI, | ||||
DEPOSIT_STATUS_LOAD_FAILURE, | DEPOSIT_STATUS_LOAD_FAILURE, | ||||
DEPOSIT_STATUS_LOAD_SUCCESS, | DEPOSIT_STATUS_LOAD_SUCCESS, | ||||
DEPOSIT_STATUS_PARTIAL, | DEPOSIT_STATUS_PARTIAL, | ||||
SE_IRI, | SE_IRI, | ||||
) | ) | ||||
from swh.deposit.models import Deposit | from swh.deposit.models import Deposit | ||||
from swh.deposit.parsers import parse_xml | from swh.deposit.parsers import parse_xml | ||||
from swh.deposit.tests.common import post_atom | |||||
from ..conftest import create_deposit | from ..conftest import create_deposit | ||||
def test_act_on_deposit_rejected_is_not_permitted( | def test_act_on_deposit_rejected_is_not_permitted( | ||||
authenticated_client, deposit_collection, rejected_deposit, atom_dataset | authenticated_client, deposit_collection, rejected_deposit, atom_dataset | ||||
): | ): | ||||
deposit = rejected_deposit | deposit = rejected_deposit | ||||
response = authenticated_client.post( | response = post_atom( | ||||
authenticated_client, | |||||
reverse(SE_IRI, args=[deposit.collection.name, deposit.id]), | reverse(SE_IRI, args=[deposit.collection.name, deposit.id]), | ||||
content_type="application/atom+xml;type=entry", | |||||
data=atom_dataset["entry-data1"], | data=atom_dataset["entry-data1"], | ||||
HTTP_SLUG=deposit.external_id, | HTTP_SLUG=deposit.external_id, | ||||
) | ) | ||||
assert response.status_code == status.HTTP_400_BAD_REQUEST | assert response.status_code == status.HTTP_400_BAD_REQUEST | ||||
msg = "You can only act on deposit with status '%s'" % ( | msg = "You can only act on deposit with status '%s'" % ( | ||||
DEPOSIT_STATUS_PARTIAL, | DEPOSIT_STATUS_PARTIAL, | ||||
) | ) | ||||
Show All 10 Lines | ): | ||||
"""Posting deposit on collection when previous is partial makes new deposit | """Posting deposit on collection when previous is partial makes new deposit | ||||
""" | """ | ||||
deposit = partial_deposit | deposit = partial_deposit | ||||
assert deposit.status == DEPOSIT_STATUS_PARTIAL | assert deposit.status == DEPOSIT_STATUS_PARTIAL | ||||
origin_url = deposit_user.provider_url + deposit.external_id | origin_url = deposit_user.provider_url + deposit.external_id | ||||
# adding a new deposit with the same external id | # adding a new deposit with the same external id | ||||
response = authenticated_client.post( | response = post_atom( | ||||
authenticated_client, | |||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
content_type="application/atom+xml;type=entry", | |||||
data=atom_dataset["entry-data0"] % origin_url, | data=atom_dataset["entry-data0"] % origin_url, | ||||
HTTP_SLUG=deposit.external_id, | HTTP_SLUG=deposit.external_id, | ||||
) | ) | ||||
assert response.status_code == status.HTTP_201_CREATED, response.content.decode() | assert response.status_code == status.HTTP_201_CREATED, response.content.decode() | ||||
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"] | ||||
Show All 12 Lines | ): | ||||
""" | """ | ||||
deposit = failed_deposit | deposit = failed_deposit | ||||
assert deposit.status == DEPOSIT_STATUS_LOAD_FAILURE | assert deposit.status == DEPOSIT_STATUS_LOAD_FAILURE | ||||
origin_url = deposit_user.provider_url + deposit.external_id | origin_url = deposit_user.provider_url + deposit.external_id | ||||
# adding a new deposit with the same external id as a completed deposit | # adding a new deposit with the same external id as a completed deposit | ||||
# creates the parenting chain | # creates the parenting chain | ||||
response = authenticated_client.post( | response = post_atom( | ||||
authenticated_client, | |||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
content_type="application/atom+xml;type=entry", | |||||
data=atom_dataset["entry-data0"] % origin_url, | data=atom_dataset["entry-data0"] % origin_url, | ||||
HTTP_SLUG=deposit.external_id, | HTTP_SLUG=deposit.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)) | ||||
deposit_id = response_content["swh:deposit_id"] | deposit_id = response_content["swh:deposit_id"] | ||||
Show All 17 Lines | ): | ||||
""" | """ | ||||
# given multiple deposit already loaded | # given multiple deposit already loaded | ||||
deposit = completed_deposit | deposit = completed_deposit | ||||
assert deposit.status == DEPOSIT_STATUS_LOAD_SUCCESS | assert deposit.status == DEPOSIT_STATUS_LOAD_SUCCESS | ||||
origin_url = deposit_user.provider_url + deposit.external_id | origin_url = deposit_user.provider_url + deposit.external_id | ||||
# adding a new deposit with the same external id as a completed deposit | # adding a new deposit with the same external id as a completed deposit | ||||
# creates the parenting chain | # creates the parenting chain | ||||
response = authenticated_client.post( | response = post_atom( | ||||
authenticated_client, | |||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
content_type="application/atom+xml;type=entry", | |||||
data=atom_dataset["entry-data0"] % origin_url, | data=atom_dataset["entry-data0"] % origin_url, | ||||
HTTP_SLUG=deposit.external_id, | HTTP_SLUG=deposit.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)) | ||||
deposit_id = response_content["swh:deposit_id"] | deposit_id = response_content["swh:deposit_id"] | ||||
Show All 28 Lines | other_deposit = create_deposit( | ||||
another_authenticated_client, | another_authenticated_client, | ||||
deposit_another_collection.name, | deposit_another_collection.name, | ||||
sample_archive, | sample_archive, | ||||
external_id, | external_id, | ||||
DEPOSIT_STATUS_LOAD_SUCCESS, | DEPOSIT_STATUS_LOAD_SUCCESS, | ||||
) | ) | ||||
# adding a new deposit with the same external id as a completed deposit | # adding a new deposit with the same external id as a completed deposit | ||||
response = authenticated_client.post( | response = post_atom( | ||||
authenticated_client, | |||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
content_type="application/atom+xml;type=entry", | |||||
data=atom_dataset["entry-data0"] % origin_url, | data=atom_dataset["entry-data0"] % origin_url, | ||||
HTTP_SLUG=external_id, | 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)) | ||||
deposit_id = response_content["swh:deposit_id"] | deposit_id = response_content["swh:deposit_id"] | ||||
Show All 31 Lines | other_deposit = create_deposit( | ||||
another_authenticated_client, | another_authenticated_client, | ||||
deposit_another_collection.name, | deposit_another_collection.name, | ||||
sample_archive, | sample_archive, | ||||
deposit.external_id, | deposit.external_id, | ||||
DEPOSIT_STATUS_LOAD_SUCCESS, | DEPOSIT_STATUS_LOAD_SUCCESS, | ||||
) | ) | ||||
# adding a new deposit with the same external id as a completed deposit | # adding a new deposit with the same external id as a completed deposit | ||||
response = authenticated_client.post( | response = post_atom( | ||||
authenticated_client, | |||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
content_type="application/atom+xml;type=entry", | |||||
data=atom_dataset["entry-data0"] % origin_url, | data=atom_dataset["entry-data0"] % origin_url, | ||||
HTTP_SLUG=deposit.external_id, | HTTP_SLUG=deposit.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)) | ||||
deposit_id = response_content["swh:deposit_id"] | deposit_id = response_content["swh:deposit_id"] | ||||
Show All 9 Lines |