Skip to content

Commit

Permalink
Merge pull request #140 from fair-workflows/click-callback-3-args
Browse files Browse the repository at this point in the history
Use 3-arg click callback for `validate_orcid_id`
  • Loading branch information
svenvanderburg authored Aug 10, 2021
2 parents 859c68b + 90fcd70 commit ed39c5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions nanopub/setup_nanopub_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
ORCID_ID_REGEX = r'^https://orcid.org/(\d{4}-){3}\d{3}(\d|X)$'


def validate_orcid_id(ctx, orcid_id: str):
def validate_orcid_id(ctx, param, orcid_id: str):
"""
Check if valid ORCID iD, should be https://orcid.org/ + 16 digit in form:
https://orcid.org/0000-0000-0000-0000
https://orcid.org/0000-0000-0000-0000. ctx and param are
necessary `click` callback arguments
"""
if re.match(ORCID_ID_REGEX, orcid_id):
return orcid_id
Expand Down
4 changes: 2 additions & 2 deletions tests/test_setup_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_validate_orcid_id():
valid_ids = ['https://orcid.org/1234-5678-1234-5678',
'https://orcid.org/1234-5678-1234-567X']
for orcid_id in valid_ids:
assert validate_orcid_id(ctx=None, orcid_id=orcid_id) == orcid_id
assert validate_orcid_id(ctx=None, param=None, orcid_id=orcid_id) == orcid_id

invalid_ids = ['https://orcid.org/abcd-efgh-abcd-efgh',
'https://orcid.org/1234-5678-1234-567',
Expand All @@ -112,4 +112,4 @@ def test_validate_orcid_id():
'0000-0000-0000-0000']
for orcid_id in invalid_ids:
with pytest.raises(ValueError):
validate_orcid_id(ctx=None, orcid_id=orcid_id)
validate_orcid_id(ctx=None, param=None, orcid_id=orcid_id)

0 comments on commit ed39c5e

Please sign in to comment.