Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_deposit_private_check.py
# Copyright (C) 2017-2019 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.private.deposit_check import ( | from swh.deposit.api.private.deposit_check import ( | ||||
ALTERNATE_FIELDS_MISSING, | |||||
MANDATORY_ARCHIVE_INVALID, | MANDATORY_ARCHIVE_INVALID, | ||||
MANDATORY_ARCHIVE_MISSING, | MANDATORY_ARCHIVE_MISSING, | ||||
MANDATORY_ARCHIVE_UNSUPPORTED, | MANDATORY_ARCHIVE_UNSUPPORTED, | ||||
MANDATORY_FIELDS_MISSING, | |||||
) | ) | ||||
from swh.deposit.config import ( | from swh.deposit.config import ( | ||||
COL_IRI, | COL_IRI, | ||||
DEPOSIT_STATUS_DEPOSITED, | DEPOSIT_STATUS_DEPOSITED, | ||||
DEPOSIT_STATUS_REJECTED, | DEPOSIT_STATUS_REJECTED, | ||||
DEPOSIT_STATUS_VERIFIED, | DEPOSIT_STATUS_VERIFIED, | ||||
PRIVATE_CHECK_DEPOSIT, | PRIVATE_CHECK_DEPOSIT, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | for url in private_check_url_endpoints(deposit_collection, deposit): | ||||
assert data["status"] == DEPOSIT_STATUS_VERIFIED | assert data["status"] == DEPOSIT_STATUS_VERIFIED | ||||
deposit = Deposit.objects.get(pk=deposit.id) | deposit = Deposit.objects.get(pk=deposit.id) | ||||
assert deposit.status == DEPOSIT_STATUS_VERIFIED | assert deposit.status == DEPOSIT_STATUS_VERIFIED | ||||
deposit.status = DEPOSIT_STATUS_DEPOSITED | deposit.status = DEPOSIT_STATUS_DEPOSITED | ||||
deposit.save() | deposit.save() | ||||
def test_check_metadata_ok(swh_checks_deposit): | |||||
actual_check, detail = swh_checks_deposit._check_metadata( | |||||
{ | |||||
"url": "something", | |||||
"external_identifier": "something-else", | |||||
"name": "foo", | |||||
"author": "someone", | |||||
} | |||||
) | |||||
assert actual_check is True | |||||
assert detail is None | |||||
def test_check_metadata_ok2(swh_checks_deposit): | |||||
actual_check, detail = swh_checks_deposit._check_metadata( | |||||
{ | |||||
"url": "something", | |||||
"external_identifier": "something-else", | |||||
"title": "bar", | |||||
"author": "someone", | |||||
} | |||||
) | |||||
assert actual_check is True | |||||
assert detail is None | |||||
def test_check_metadata_ko(swh_checks_deposit): | |||||
"""Missing optional field should be caught | |||||
""" | |||||
actual_check, error_detail = swh_checks_deposit._check_metadata( | |||||
{ | |||||
"url": "something", | |||||
"external_identifier": "something-else", | |||||
"author": "someone", | |||||
} | |||||
) | |||||
expected_error = { | |||||
"metadata": [ | |||||
{ | |||||
"summary": "Mandatory alternate fields are missing", | |||||
"fields": ["name or title"], | |||||
} | |||||
] | |||||
} | |||||
assert actual_check is False | |||||
assert error_detail == expected_error | |||||
def test_check_metadata_ko2(swh_checks_deposit): | |||||
"""Missing mandatory fields should be caught | |||||
""" | |||||
actual_check, error_detail = swh_checks_deposit._check_metadata( | |||||
{ | |||||
"url": "something", | |||||
"external_identifier": "something-else", | |||||
"title": "foobar", | |||||
} | |||||
) | |||||
expected_error = { | |||||
"metadata": [{"summary": "Mandatory fields are missing", "fields": ["author"],}] | |||||
} | |||||
assert actual_check is False | |||||
assert error_detail == expected_error | |||||
def create_deposit_archive_with_archive( | def create_deposit_archive_with_archive( | ||||
root_path, archive_extension, client, collection_name | root_path, archive_extension, client, collection_name | ||||
): | ): | ||||
# we create the holding archive to a given extension | # we create the holding archive to a given extension | ||||
archive = create_arborescence_archive( | archive = create_arborescence_archive( | ||||
root_path, | root_path, | ||||
"archive1", | "archive1", | ||||
"file1", | "file1", | ||||
Show All 29 Lines |