Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_private_check.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 | ||||
import pytest | import pytest | ||||
from rest_framework import status | from rest_framework import status | ||||
from swh.deposit.api.checks import ALTERNATE_FIELDS_MISSING, MANDATORY_FIELDS_MISSING | from swh.deposit.api.checks import MANDATORY_FIELDS_MISSING | ||||
from swh.deposit.api.private.deposit_check import ( | from swh.deposit.api.private.deposit_check import ( | ||||
MANDATORY_ARCHIVE_INVALID, | MANDATORY_ARCHIVE_INVALID, | ||||
MANDATORY_ARCHIVE_MISSING, | MANDATORY_ARCHIVE_MISSING, | ||||
MANDATORY_ARCHIVE_UNSUPPORTED, | MANDATORY_ARCHIVE_UNSUPPORTED, | ||||
) | ) | ||||
from swh.deposit.config import ( | from swh.deposit.config import ( | ||||
COL_IRI, | COL_IRI, | ||||
DEPOSIT_STATUS_DEPOSITED, | DEPOSIT_STATUS_DEPOSITED, | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | for url in private_check_url_endpoints(deposit_collection, deposit): | ||||
data = response.json() | data = response.json() | ||||
assert data["status"] == DEPOSIT_STATUS_REJECTED | assert data["status"] == DEPOSIT_STATUS_REJECTED | ||||
details = data["details"] | details = data["details"] | ||||
# archive checks failure | # archive checks failure | ||||
assert len(details["archive"]) == 1 | assert len(details["archive"]) == 1 | ||||
assert details["archive"][0]["summary"] == MANDATORY_ARCHIVE_UNSUPPORTED | assert details["archive"][0]["summary"] == MANDATORY_ARCHIVE_UNSUPPORTED | ||||
# metadata check failure | # metadata check failure | ||||
assert len(details["metadata"]) == 2 | assert len(details["metadata"]) == 1 | ||||
mandatory = details["metadata"][0] | mandatory = details["metadata"][0] | ||||
assert mandatory["summary"] == MANDATORY_FIELDS_MISSING | assert mandatory["summary"] == MANDATORY_FIELDS_MISSING | ||||
assert set(mandatory["fields"]) == set(["atom:author"]) | assert set(mandatory["fields"]) == set( | ||||
alternate = details["metadata"][1] | [ | ||||
assert alternate["summary"] == ALTERNATE_FIELDS_MISSING | "atom:author or codemeta:author", | ||||
assert alternate["fields"] == ["atom:name or atom:title"] | "atom:name or atom:title or codemeta:name", | ||||
] | |||||
) | |||||
deposit = Deposit.objects.get(pk=deposit.id) | deposit = Deposit.objects.get(pk=deposit.id) | ||||
assert deposit.status == DEPOSIT_STATUS_REJECTED | assert deposit.status == DEPOSIT_STATUS_REJECTED | ||||
deposit.status = DEPOSIT_STATUS_DEPOSITED | deposit.status = DEPOSIT_STATUS_DEPOSITED | ||||
deposit.save() | deposit.save() | ||||
▲ Show 20 Lines • Show All 62 Lines • Show Last 20 Lines |