Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_private_read_metadata.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-2020 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 django.urls import reverse | from django.urls import reverse | ||||
from rest_framework import status | from rest_framework import status | ||||
from swh.deposit import __version__, utils | from swh.deposit import __version__, utils | ||||
from swh.deposit.config import EDIT_SE_IRI, PRIVATE_GET_DEPOSIT_METADATA, SWH_PERSON | from swh.deposit.config import PRIVATE_GET_DEPOSIT_METADATA, SE_IRI, SWH_PERSON | ||||
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 | ||||
PRIVATE_GET_DEPOSIT_METADATA_NC = PRIVATE_GET_DEPOSIT_METADATA + "-nc" | PRIVATE_GET_DEPOSIT_METADATA_NC = PRIVATE_GET_DEPOSIT_METADATA + "-nc" | ||||
def private_get_raw_url_endpoints(collection, deposit): | def private_get_raw_url_endpoints(collection, deposit): | ||||
"""There are 2 endpoints to check (one with collection, one without)""" | """There are 2 endpoints to check (one with collection, one without)""" | ||||
deposit_id = deposit if isinstance(deposit, int) else deposit.id | deposit_id = deposit if isinstance(deposit, int) else deposit.id | ||||
return [ | return [ | ||||
reverse(PRIVATE_GET_DEPOSIT_METADATA, args=[collection.name, deposit_id]), | reverse(PRIVATE_GET_DEPOSIT_METADATA, args=[collection.name, deposit_id]), | ||||
reverse(PRIVATE_GET_DEPOSIT_METADATA_NC, args=[deposit_id]), | reverse(PRIVATE_GET_DEPOSIT_METADATA_NC, args=[deposit_id]), | ||||
] | ] | ||||
def update_deposit_with_metadata(authenticated_client, collection, deposit, metadata): | def update_deposit_with_metadata(authenticated_client, collection, deposit, metadata): | ||||
# update deposit's metadata | # update deposit's metadata | ||||
response = authenticated_client.post( | response = authenticated_client.post( | ||||
reverse(EDIT_SE_IRI, args=[collection.name, deposit.id]), | reverse(SE_IRI, args=[collection.name, deposit.id]), | ||||
content_type="application/atom+xml;type=entry", | content_type="application/atom+xml;type=entry", | ||||
data=metadata, | data=metadata, | ||||
HTTP_SLUG=deposit.external_id, | HTTP_SLUG=deposit.external_id, | ||||
HTTP_IN_PROGRESS=True, | HTTP_IN_PROGRESS=True, | ||||
) | ) | ||||
assert response.status_code == status.HTTP_201_CREATED | assert response.status_code == status.HTTP_201_CREATED | ||||
return deposit | return deposit | ||||
▲ Show 20 Lines • Show All 361 Lines • Show Last 20 Lines |