Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_checks.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 | ||||
import pytest | import pytest | ||||
from swh.deposit.api.checks import check_metadata | from swh.deposit.api.checks import check_metadata | ||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"metadata_ok", | "metadata_ok", | ||||
[ | [ | ||||
{ | { | ||||
"url": "something", | "atom:url": "something", | ||||
"external_identifier": "something-else", | "atom:external_identifier": "something-else", | ||||
"name": "foo", | "atom:name": "foo", | ||||
"author": "someone", | "atom:author": "someone", | ||||
}, | }, | ||||
{ | { | ||||
"url": "some url", | "atom:url": "some url", | ||||
"external_identifier": "some id", | "atom:external_identifier": "some id", | ||||
"title": "bar", | "atom:title": "bar", | ||||
"author": "no one", | "atom:author": "no one", | ||||
}, | }, | ||||
], | ], | ||||
) | ) | ||||
def test_api_checks_check_metadata_ok(metadata_ok, swh_checks_deposit): | def test_api_checks_check_metadata_ok(metadata_ok, swh_checks_deposit): | ||||
actual_check, detail = check_metadata(metadata_ok) | actual_check, detail = check_metadata(metadata_ok) | ||||
assert actual_check is True | assert actual_check is True | ||||
assert detail is None | assert detail is None | ||||
@pytest.mark.parametrize( | @pytest.mark.parametrize( | ||||
"metadata_ko,expected_summary", | "metadata_ko,expected_summary", | ||||
[ | [ | ||||
( | ( | ||||
{ | { | ||||
"url": "something", | "atom:url": "something", | ||||
"external_identifier": "something-else", | "atom:external_identifier": "something-else", | ||||
"author": "someone", | "atom:author": "someone", | ||||
}, | }, | ||||
{ | { | ||||
"summary": "Mandatory alternate fields are missing", | "summary": "Mandatory alternate fields are missing", | ||||
"fields": ["name or title"], | "fields": ["atom:name or atom:title"], | ||||
}, | }, | ||||
), | ), | ||||
( | ( | ||||
{ | { | ||||
"url": "something", | "atom:url": "something", | ||||
"external_identifier": "something-else", | "atom:external_identifier": "something-else", | ||||
"title": "foobar", | "atom:title": "foobar", | ||||
}, | }, | ||||
{"summary": "Mandatory fields are missing", "fields": ["author"],}, | {"summary": "Mandatory fields are missing", "fields": ["atom:author"],}, | ||||
), | ), | ||||
], | ], | ||||
) | ) | ||||
def test_api_checks_check_metadata_ko( | def test_api_checks_check_metadata_ko( | ||||
metadata_ko, expected_summary, swh_checks_deposit | metadata_ko, expected_summary, swh_checks_deposit | ||||
): | ): | ||||
"""Missing optional field should be caught | """Missing optional field should be caught | ||||
""" | """ | ||||
actual_check, error_detail = check_metadata(metadata_ko) | actual_check, error_detail = check_metadata(metadata_ko) | ||||
assert actual_check is False | assert actual_check is False | ||||
assert error_detail == {"metadata": [expected_summary]} | assert error_detail == {"metadata": [expected_summary]} |