diff --git a/ezidapp/models/validation.py b/ezidapp/models/validation.py index 7f6b93c09..74e64c2be 100644 --- a/ezidapp/models/validation.py +++ b/ezidapp/models/validation.py @@ -114,7 +114,7 @@ def publicationDate(date): # return ("%04d", "%04d-%02d", "%04d-%02d-%02d")[numComponents - 1] % t[:numComponents] return ("{:04d}", "{:04d}-{:02d}", "{:04d}-{:02d}-{:02d}")[ numComponents - 1 - ].format(t[:numComponents]) + ].format(*t[:numComponents]) except Exception: pass raise django.core.exceptions.ValidationError( diff --git a/tests/test_docs/datacite_metadata_01.txt b/tests/test_docs/datacite_metadata_01.txt new file mode 100644 index 000000000..af3ee31c6 --- /dev/null +++ b/tests/test_docs/datacite_metadata_01.txt @@ -0,0 +1,7 @@ +# For input to client testing datacite minting +# client.py l admin mint doi:10.5072/FK2 @datacite_metadata_01.txt +datacite.creator: Dave +datacite.title: Test doc +datacite.publicationyear: 1961 +datacite.resourcetype: Event +datacite.publisher: Tester diff --git a/tests/test_validation.py b/tests/test_validation.py new file mode 100644 index 000000000..1fdcfd6ef --- /dev/null +++ b/tests/test_validation.py @@ -0,0 +1,20 @@ +# Copyright©2021, Regents of the University of California +# http://creativecommons.org/licenses/BSD + +"""Test ezidapp.models.validation +""" + +import pytest + +import ezidapp.models.validation + +#TODO: Flesh out the test cases to match all the possibilities in the tested method +@pytest.mark.parametrize("test,expected",[ + ('1961', '1961'), + ('196104','1961-04'), + ('20201201', '2020-12-01'), +]) +def test_publicationDate(test, expected): + res = ezidapp.models.validation.publicationDate(test) + assert res == expected +