Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_collection_reuse_slug.py
Show All 13 Lines | from swh.deposit.config import ( | ||||
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 swh.deposit.tests.common import post_atom | ||||
from ..conftest import create_deposit | from ..conftest import internal_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 = post_atom( | response = post_atom( | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | ): | ||||
assert new_deposit != deposit | assert new_deposit != deposit | ||||
assert new_deposit.parent == deposit | assert new_deposit.parent == deposit | ||||
assert new_deposit.origin_url == origin_url | assert new_deposit.origin_url == origin_url | ||||
def test_add_deposit_external_id_conflict_no_parent( | def test_add_deposit_external_id_conflict_no_parent( | ||||
authenticated_client, | authenticated_client, | ||||
another_authenticated_client, | |||||
deposit_collection, | deposit_collection, | ||||
deposit_another_collection, | deposit_another_collection, | ||||
atom_dataset, | atom_dataset, | ||||
sample_archive, | |||||
deposit_user, | deposit_user, | ||||
deposit_another_user, | |||||
): | ): | ||||
"""Posting a deposit with an external_id conflicting with an external_id | """Posting a deposit with an external_id conflicting with an external_id | ||||
of a different client does not create a parent relationship | of a different client does not create a parent relationship | ||||
""" | """ | ||||
external_id = "foobar" | external_id = "foobar" | ||||
origin_url = deposit_user.provider_url + external_id | origin_url = deposit_user.provider_url + external_id | ||||
# create a deposit for that other user, with the same slug | # create a deposit for that other user, with the same slug | ||||
other_deposit = create_deposit( | other_deposit = internal_create_deposit( | ||||
another_authenticated_client, | deposit_another_user, | ||||
deposit_another_collection.name, | deposit_another_collection, | ||||
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 = post_atom( | response = post_atom( | ||||
authenticated_client, | authenticated_client, | ||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
Show All 10 Lines | ): | ||||
new_deposit = Deposit.objects.get(pk=deposit_id) | new_deposit = Deposit.objects.get(pk=deposit_id) | ||||
assert new_deposit.parent is None | assert new_deposit.parent is None | ||||
assert new_deposit.origin_url == origin_url | assert new_deposit.origin_url == origin_url | ||||
def test_add_deposit_external_id_conflict_with_parent( | def test_add_deposit_external_id_conflict_with_parent( | ||||
authenticated_client, | authenticated_client, | ||||
another_authenticated_client, | |||||
deposit_collection, | deposit_collection, | ||||
deposit_another_collection, | deposit_another_collection, | ||||
completed_deposit, | completed_deposit, | ||||
atom_dataset, | atom_dataset, | ||||
sample_archive, | |||||
deposit_user, | deposit_user, | ||||
deposit_another_user, | |||||
): | ): | ||||
"""Posting a deposit with an external_id conflicting with an external_id | """Posting a deposit with an external_id conflicting with an external_id | ||||
of a different client creates a parent relationship with the deposit | of a different client creates a parent relationship with the deposit | ||||
of the right client instead of the last matching deposit | of the right client instead of the last matching deposit | ||||
This test does not have an equivalent for origin url conflicts, as these | This test does not have an equivalent for origin url conflicts, as these | ||||
can not happen (assuming clients do not have provider_url overlaps) | can not happen (assuming clients do not have provider_url overlaps) | ||||
""" | """ | ||||
# 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 | ||||
# create a deposit for that other user, with the same slug | # create a deposit for that other user, with the same slug | ||||
other_deposit = create_deposit( | other_deposit = internal_create_deposit( | ||||
another_authenticated_client, | deposit_another_user, | ||||
deposit_another_collection.name, | deposit_another_collection, | ||||
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 = post_atom( | response = post_atom( | ||||
authenticated_client, | authenticated_client, | ||||
reverse(COL_IRI, args=[deposit_collection.name]), | reverse(COL_IRI, args=[deposit_collection.name]), | ||||
Show All 18 Lines |