Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_collection_add_to_origin.py
# Copyright (C) 2017-2021 The Software Heritage developers | # Copyright (C) 2017-2021 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from io import BytesIO | from io import BytesIO | ||||
from django.urls import reverse_lazy as reverse | from django.urls import reverse_lazy as reverse | ||||
from rest_framework import status | from rest_framework import status | ||||
from swh.deposit.config import COL_IRI, DEPOSIT_STATUS_LOAD_SUCCESS | from swh.deposit.config import COL_IRI, DEPOSIT_STATUS_LOAD_SUCCESS | ||||
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_add_deposit_with_add_to_origin( | def test_add_deposit_with_add_to_origin( | ||||
authenticated_client, | authenticated_client, | ||||
deposit_collection, | deposit_collection, | ||||
completed_deposit, | completed_deposit, | ||||
atom_dataset, | atom_dataset, | ||||
deposit_user, | deposit_user, | ||||
Show All 26 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_add_to_origin_conflict( | def test_add_deposit_add_to_origin_conflict( | ||||
authenticated_client, | authenticated_client, | ||||
another_authenticated_client, | |||||
deposit_collection, | deposit_collection, | ||||
deposit_another_collection, | deposit_another_collection, | ||||
atom_dataset, | atom_dataset, | ||||
sample_archive, | sample_archive, | ||||
deposit_user, | deposit_user, | ||||
deposit_another_user, | deposit_another_user, | ||||
): | ): | ||||
"""Posting a deposit with an <swh:add_to_origin> referencing an origin | """Posting a deposit with an <swh:add_to_origin> referencing an origin | ||||
owned by a different client raises an error | owned by a different client raises an error | ||||
""" | """ | ||||
external_id = "foobar" | external_id = "foobar" | ||||
origin_url = deposit_another_user.provider_url + external_id | origin_url = deposit_another_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 | ||||
create_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 20 Lines • Show All 73 Lines • Show Last 20 Lines |