diff --git a/swh/deposit/tests/api/test_checks.py b/swh/deposit/tests/api/test_checks.py --- a/swh/deposit/tests/api/test_checks.py +++ b/swh/deposit/tests/api/test_checks.py @@ -3,76 +3,64 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +import pytest + from swh.deposit.api.checks import check_metadata -def test_api_checks_check_metadata_ok(swh_checks_deposit): - actual_check, detail = check_metadata( +@pytest.mark.parametrize( + "metadata_ok", + [ { "url": "something", "external_identifier": "something-else", "name": "foo", "author": "someone", - } - ) - - assert actual_check is True - assert detail is None - - -def test_api_checks_check_metadata_ok2(swh_checks_deposit): - actual_check, detail = check_metadata( + }, { - "url": "something", - "external_identifier": "something-else", + "url": "some url", + "external_identifier": "some id", "title": "bar", - "author": "someone", - } - ) - + "author": "no one", + }, + ], +) +def test_api_checks_check_metadata_ok(metadata_ok, swh_checks_deposit): + actual_check, detail = check_metadata(metadata_ok) assert actual_check is True assert detail is None -def test_api_checks_check_metadata_ko(swh_checks_deposit): - """Missing optional field should be caught - - """ - actual_check, error_detail = check_metadata( - { - "url": "something", - "external_identifier": "something-else", - "author": "someone", - } - ) - - expected_error = { - "metadata": [ +@pytest.mark.parametrize( + "metadata_ko,expected_summary", + [ + ( + { + "url": "something", + "external_identifier": "something-else", + "author": "someone", + }, { "summary": "Mandatory alternate fields are missing", "fields": ["name or title"], - } - ] - } - assert actual_check is False - assert error_detail == expected_error - - -def test_api_checks_check_metadata_ko2(swh_checks_deposit): - """Missing mandatory fields should be caught + }, + ), + ( + { + "url": "something", + "external_identifier": "something-else", + "title": "foobar", + }, + {"summary": "Mandatory fields are missing", "fields": ["author"],}, + ), + ], +) +def test_api_checks_check_metadata_ko( + metadata_ko, expected_summary, swh_checks_deposit +): + """Missing optional field should be caught """ - actual_check, error_detail = check_metadata( - { - "url": "something", - "external_identifier": "something-else", - "title": "foobar", - } - ) - - expected_error = { - "metadata": [{"summary": "Mandatory fields are missing", "fields": ["author"],}] - } - + actual_check, error_detail = check_metadata(metadata_ko) assert actual_check is False - assert error_detail == expected_error + assert error_detail == {"metadata": [expected_summary]}