From ffd2597d5e962e3f3a2ea23c66a135bb737b2390 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Thu, 9 Jan 2020 15:02:17 +0100 Subject: datacite: improve license_slug handling --- python/tests/import_datacite.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'python/tests/import_datacite.py') diff --git a/python/tests/import_datacite.py b/python/tests/import_datacite.py index 5ad7ef2c..89671cd2 100644 --- a/python/tests/import_datacite.py +++ b/python/tests/import_datacite.py @@ -7,7 +7,7 @@ import datetime import pytest import gzip from fatcat_tools.importers import DataciteImporter, JsonLinePusher -from fatcat_tools.importers.datacite import find_original_language_title, parse_datacite_titles, parse_datacite_dates, clean_doi, index_form_to_display_name +from fatcat_tools.importers.datacite import find_original_language_title, parse_datacite_titles, parse_datacite_dates, clean_doi, index_form_to_display_name, lookup_license_slug from fatcat_tools.transforms import entity_to_dict from fixtures import api import json @@ -315,3 +315,32 @@ def test_index_form_to_display_name(): for c in cases: assert c.output == index_form_to_display_name(c.input) + +def test_lookup_license_slug(): + Case = collections.namedtuple('Case', 'input output') + cases = [ + Case('https://opensource.org/licenses/MIT', 'MIT'), + Case('creativecommons.org/licenses/by-nc-nd/3.0/', 'CC-BY-NC-ND'), + Case('http://creativecommons.org/licences/by-nc-sa/4.0', 'CC-BY-NC-SA'), + Case('http://creativecommons.org/licenses/by-nc-nd/2.5/co', 'CC-BY-NC-ND'), + Case('http://creativecommons.org/licenses/by-nd/4.0/legalcode', 'CC-BY-ND'), + Case('http://creativecommons.org/licenses/by/2.0/uk/legalcode', 'CC-BY'), + Case('http://creativecommons.org/publicdomain/zero/1.0/legalcode', 'CC-0'), + Case('http://doi.wiley.com/10.1002/tdm_license_1.1', 'WILEY-TDM-1.1'), + Case('http://homepage.data-planet.com/terms-use', 'SAGE-DATA-PLANET'), + Case('http://www.springer.com/tdm', 'SPRINGER-TDM'), + Case('https://archaeologydataservice.ac.uk/advice/termsOfUseAndAccess.xhtml', 'ADS-UK'), + Case('https://creativecommons.org/public-domain/cc0', 'CC-0'), + Case('https://creativecommons.org/publicdomain/zero/1.0', 'CC-0'), + Case('https://creativecommons.org/share-your-work/public-domain/cc0', 'CC-0'), + Case('https://www.elsevier.com/tdm/userlicense/1.0', 'ELSEVIER-USER-1.0'), + Case('https://www.gnu.org/licenses/gpl-3.0.html', 'GPL-3.0'), + Case('http://rightsstatements.org/page/InC/1.0?language=en', 'RS-INC'), + Case('http://onlinelibrary.wiley.com/termsAndConditions', 'WILEY'), + Case('https://publikationen.bibliothek.kit.edu/kitopen-lizenz', 'KIT-OPEN'), + Case('http://journals.sagepub.com/page/policies/text-and-data-mining-license', 'SAGE-TDM'), + ] + + for c in cases: + got = lookup_license_slug(c.input) + assert c.output == got, '{}: got {}, want {}'.format(c.input, got, c.output) -- cgit v1.2.3