From 6e746e8229004efc41d0df04aa7ac3dcfcbe2d3b Mon Sep 17 00:00:00 2001 From: Martin Lessmeister Date: Thu, 10 May 2018 15:02:36 -0400 Subject: [PATCH 1/6] Add license definitions and simple first test --- arxiv/license.py | 114 ++++++++++++++++++++++++++++++++++++ arxiv/tests/test_license.py | 21 +++++++ 2 files changed, 135 insertions(+) create mode 100644 arxiv/license.py create mode 100644 arxiv/tests/test_license.py diff --git a/arxiv/license.py b/arxiv/license.py new file mode 100644 index 00000000..be54ba92 --- /dev/null +++ b/arxiv/license.py @@ -0,0 +1,114 @@ +"""arXiv license definitions.""" + + +LICENSE_ICON_BASE_URI = '/icons/licenses' +LICENSES = { + 'http://arxiv.org/licenses/nonexclusive-distrib/1.0/': { + 'uri': 'http://arxiv.org/licenses/nonexclusive-distrib/1.0/', + 'label': 'arXiv.org perpetual, non-exclusive license to ' + 'distribute this article', + 'note': '(Minimal rights required by arXiv.org. Select this ' + 'unless you understand the implications of other ' + 'licenses)', + 'order': 1, + 'is_current': True, + 'is_valid': True, + }, + 'http://creativecommons.org/licenses/by/4.0/': { + 'uri': 'http://creativecommons.org/licenses/by/4.0/', + 'label': 'Creative Commons Attribution license', + 'order': 5, + 'is_current': True, + 'is_valid': True, + 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-4.0.png'}, + + 'http://creativecommons.org/licenses/by-sa/4.0/': { + 'uri': 'http://creativecommons.org/licenses/by-sa/4.0/', + 'order': 6, + 'label': 'Creative Commons Attribution-ShareAlike license', + 'is_current': True, + 'is_valid': True, + 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-sa-4.0.png'}, + + 'http://creativecommons.org/licenses/by-nc-sa/4.0/': { + 'uri': 'http://creativecommons.org/licenses/by-nc-sa/4.0/', + 'order': 7, + 'label': 'Creative Commons Attribution-Noncommercial-ShareAlike ' + ' license', + 'is_current': True, + 'is_valid': True, + 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-nc-sa-4.0.png'}, + + 'http://creativecommons.org/publicdomain/zero/1.0/': { + 'uri': 'http://creativecommons.org/publicdomain/zero/1.0/', + 'label': 'Creative Commons Public Domain Declaration', + 'order': 8, + 'is_current': True, + 'is_valid': True, + 'icon_uri': f'{LICENSE_ICON_BASE_URI}/zero-1.0.png' + }, + + 'http://arxiv.org/licenses/assumed-1991-2003/': { + 'uri': 'http://arxiv.org/licenses/assumed-1991-2003/', + 'label': 'Assumed arXiv.org perpetual, non-exclusive license to ' + 'distribute this article for submissions made before ' + 'January 2004', + 'order': 9, + 'is_current': False, + 'is_valid': True, + }, + + 'http://creativecommons.org/licenses/by/3.0/': { + 'uri': 'http://creativecommons.org/licenses/by/3.0/', + 'label': 'Creative Commons Attribution license', + 'order': 2, + 'is_current': False, + 'is_valid': True, + 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-3.0.png' + }, + + 'http://creativecommons.org/licenses/by-nc-sa/3.0/': { + 'uri': 'http://creativecommons.org/licenses/by-nc-sa/3.0/', + 'label': 'Creative Commons Attribution-Noncommercial-ShareAlike ' + 'license', + 'order': 3, + 'is_current': False, + 'is_valid': True, + 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-nc-sa-3.0.png' + }, + 'http://creativecommons.org/licenses/publicdomain/': { + 'uri': 'http://creativecommons.org/licenses/publicdomain/', + 'label': 'Creative Commons Public Domain Declaration', + 'note': '(Suitable for US government employees, for example)', + 'order': 4, + 'is_current': False, + 'is_valid': True, + 'icon_uri': "$icon_baseurl/publicdomain.png" + }, + 'no_license': { + 'order': 99, + 'label': 'I do not certify that any of the above licenses apply', + 'is_valid': False + } +} + +ASSUMED_LICENSE = LICENSES['http://arxiv.org/licenses/assumed-1991-2003/'] + +# Historical license to updated/current license (old: new) +TRANSLATED_LICENSES = { + 'http://creativecommons.org/licenses/by/3.0/': + 'http://creativecommons.org/licenses/by/4.0/', + 'http://creativecommons.org/licenses/by-nc-sa/3.0/': + 'http://creativecommons.org/licenses/by-nc-sa/4.0/', + 'http://creativecommons.org/licenses/publicdomain/': + 'http://creativecommons.org/publicdomain/zero/1.0/' +} + +CURRENT_LICENSES = { + k: v for k, v in LICENSES.items() + if all(k in v for k in ('is_current', 'order')) and v['is_current'] +} + +# Current license URIs by display order +CURRENT_LICENSE_URIS = \ + sorted(CURRENT_LICENSES, key=lambda x: CURRENT_LICENSES[x]['order']) diff --git a/arxiv/tests/test_license.py b/arxiv/tests/test_license.py new file mode 100644 index 00000000..50dca8c3 --- /dev/null +++ b/arxiv/tests/test_license.py @@ -0,0 +1,21 @@ +"""Tests for arXiv taxonomy module.""" +from unittest import TestCase +from arxiv.license import LICENSES, CURRENT_LICENSE_URIS + + +class TestLicense(TestCase): + """Tests for the arXiv license definitions.""" + + def test_current_license_uris(self): + """Tests for the current active licenses.""" + self.assertListEqual( + CURRENT_LICENSE_URIS, + [ + 'http://arxiv.org/licenses/nonexclusive-distrib/1.0/', + 'http://creativecommons.org/licenses/by/4.0/', + 'http://creativecommons.org/licenses/by-sa/4.0/', + 'http://creativecommons.org/licenses/by-nc-sa/4.0/', + 'http://creativecommons.org/publicdomain/zero/1.0/' + ], + 'current license URIs match' + ) From b134858a8cf11afcb310463b908579aa6db69304 Mon Sep 17 00:00:00 2001 From: Martin Lessmeister Date: Wed, 16 May 2018 14:45:31 -0400 Subject: [PATCH 2/6] Fix indentation, use clearer syntax to generate CURRENT_LICENSES. --- arxiv/license.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arxiv/license.py b/arxiv/license.py index be54ba92..66207fdb 100644 --- a/arxiv/license.py +++ b/arxiv/license.py @@ -6,7 +6,7 @@ 'http://arxiv.org/licenses/nonexclusive-distrib/1.0/': { 'uri': 'http://arxiv.org/licenses/nonexclusive-distrib/1.0/', 'label': 'arXiv.org perpetual, non-exclusive license to ' - 'distribute this article', + 'distribute this article', 'note': '(Minimal rights required by arXiv.org. Select this ' 'unless you understand the implications of other ' 'licenses)', @@ -34,7 +34,7 @@ 'uri': 'http://creativecommons.org/licenses/by-nc-sa/4.0/', 'order': 7, 'label': 'Creative Commons Attribution-Noncommercial-ShareAlike ' - ' license', + 'license', 'is_current': True, 'is_valid': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-nc-sa-4.0.png'}, @@ -70,7 +70,7 @@ 'http://creativecommons.org/licenses/by-nc-sa/3.0/': { 'uri': 'http://creativecommons.org/licenses/by-nc-sa/3.0/', 'label': 'Creative Commons Attribution-Noncommercial-ShareAlike ' - 'license', + 'license', 'order': 3, 'is_current': False, 'is_valid': True, @@ -83,7 +83,7 @@ 'order': 4, 'is_current': False, 'is_valid': True, - 'icon_uri': "$icon_baseurl/publicdomain.png" + 'icon_uri': f'{LICENSE_ICON_BASE_URI}/publicdomain.png' }, 'no_license': { 'order': 99, @@ -106,7 +106,7 @@ CURRENT_LICENSES = { k: v for k, v in LICENSES.items() - if all(k in v for k in ('is_current', 'order')) and v['is_current'] + if 'order' in v and 'is_current' in v and v['is_current'] } # Current license URIs by display order From 7233a807cee263c5bb4b6736fa0ac9a576508b92 Mon Sep 17 00:00:00 2001 From: Martin Lessmeister Date: Wed, 16 May 2018 15:43:55 -0400 Subject: [PATCH 3/6] Simplify license struct --- arxiv/license.py | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/arxiv/license.py b/arxiv/license.py index 66207fdb..137b1210 100644 --- a/arxiv/license.py +++ b/arxiv/license.py @@ -12,14 +12,12 @@ 'licenses)', 'order': 1, 'is_current': True, - 'is_valid': True, }, 'http://creativecommons.org/licenses/by/4.0/': { 'uri': 'http://creativecommons.org/licenses/by/4.0/', 'label': 'Creative Commons Attribution license', 'order': 5, 'is_current': True, - 'is_valid': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-4.0.png'}, 'http://creativecommons.org/licenses/by-sa/4.0/': { @@ -27,7 +25,6 @@ 'order': 6, 'label': 'Creative Commons Attribution-ShareAlike license', 'is_current': True, - 'is_valid': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-sa-4.0.png'}, 'http://creativecommons.org/licenses/by-nc-sa/4.0/': { @@ -36,7 +33,6 @@ 'label': 'Creative Commons Attribution-Noncommercial-ShareAlike ' 'license', 'is_current': True, - 'is_valid': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-nc-sa-4.0.png'}, 'http://creativecommons.org/publicdomain/zero/1.0/': { @@ -44,7 +40,6 @@ 'label': 'Creative Commons Public Domain Declaration', 'order': 8, 'is_current': True, - 'is_valid': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/zero-1.0.png' }, @@ -55,7 +50,6 @@ 'January 2004', 'order': 9, 'is_current': False, - 'is_valid': True, }, 'http://creativecommons.org/licenses/by/3.0/': { @@ -63,7 +57,6 @@ 'label': 'Creative Commons Attribution license', 'order': 2, 'is_current': False, - 'is_valid': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-3.0.png' }, @@ -73,7 +66,6 @@ 'license', 'order': 3, 'is_current': False, - 'is_valid': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-nc-sa-3.0.png' }, 'http://creativecommons.org/licenses/publicdomain/': { @@ -82,15 +74,10 @@ 'note': '(Suitable for US government employees, for example)', 'order': 4, 'is_current': False, - 'is_valid': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/publicdomain.png' - }, - 'no_license': { - 'order': 99, - 'label': 'I do not certify that any of the above licenses apply', - 'is_valid': False } } +NO_LICENSE_TEXT = 'I do not certify that any of the above licenses apply' ASSUMED_LICENSE = LICENSES['http://arxiv.org/licenses/assumed-1991-2003/'] From 67dc390f424426cdbce9bf4fd5675a224051f6c7 Mon Sep 17 00:00:00 2001 From: Martin Lessmeister Date: Wed, 16 May 2018 15:51:23 -0400 Subject: [PATCH 4/6] Add license validation test --- arxiv/tests/test_license.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arxiv/tests/test_license.py b/arxiv/tests/test_license.py index 50dca8c3..0870abd0 100644 --- a/arxiv/tests/test_license.py +++ b/arxiv/tests/test_license.py @@ -7,7 +7,7 @@ class TestLicense(TestCase): """Tests for the arXiv license definitions.""" def test_current_license_uris(self): - """Tests for the current active licenses.""" + """Regression test for the current active licenses.""" self.assertListEqual( CURRENT_LICENSE_URIS, [ @@ -19,3 +19,17 @@ def test_current_license_uris(self): ], 'current license URIs match' ) + + def test_licenses_are_valid(self): + """Test licenses contain required key/values.""" + for uri, license in LICENSES.items(): + self.assertIn('label', license) + self.assertTrue(license['label']) + self.assertIn('is_current', license) + self.assertIsInstance(license['is_current'], bool) + self.assertIn('order', license) + self.assertIsInstance(license['order'], int) + if 'icon_uri' in license: + self.assertTrue(license['icon_uri']) + if 'note' in license: + self.assertTrue(license['note']) From 25cb21712701560af40fdc1b99855e3a162dfb69 Mon Sep 17 00:00:00 2001 From: Martin Lessmeister Date: Thu, 17 May 2018 08:59:50 -0400 Subject: [PATCH 5/6] Remove redundant uri --- arxiv/license.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/arxiv/license.py b/arxiv/license.py index 137b1210..81db3582 100644 --- a/arxiv/license.py +++ b/arxiv/license.py @@ -3,8 +3,8 @@ LICENSE_ICON_BASE_URI = '/icons/licenses' LICENSES = { + # key is the license URI 'http://arxiv.org/licenses/nonexclusive-distrib/1.0/': { - 'uri': 'http://arxiv.org/licenses/nonexclusive-distrib/1.0/', 'label': 'arXiv.org perpetual, non-exclusive license to ' 'distribute this article', 'note': '(Minimal rights required by arXiv.org. Select this ' @@ -14,21 +14,18 @@ 'is_current': True, }, 'http://creativecommons.org/licenses/by/4.0/': { - 'uri': 'http://creativecommons.org/licenses/by/4.0/', 'label': 'Creative Commons Attribution license', 'order': 5, 'is_current': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-4.0.png'}, 'http://creativecommons.org/licenses/by-sa/4.0/': { - 'uri': 'http://creativecommons.org/licenses/by-sa/4.0/', 'order': 6, 'label': 'Creative Commons Attribution-ShareAlike license', 'is_current': True, 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-sa-4.0.png'}, 'http://creativecommons.org/licenses/by-nc-sa/4.0/': { - 'uri': 'http://creativecommons.org/licenses/by-nc-sa/4.0/', 'order': 7, 'label': 'Creative Commons Attribution-Noncommercial-ShareAlike ' 'license', @@ -36,7 +33,6 @@ 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-nc-sa-4.0.png'}, 'http://creativecommons.org/publicdomain/zero/1.0/': { - 'uri': 'http://creativecommons.org/publicdomain/zero/1.0/', 'label': 'Creative Commons Public Domain Declaration', 'order': 8, 'is_current': True, @@ -44,7 +40,6 @@ }, 'http://arxiv.org/licenses/assumed-1991-2003/': { - 'uri': 'http://arxiv.org/licenses/assumed-1991-2003/', 'label': 'Assumed arXiv.org perpetual, non-exclusive license to ' 'distribute this article for submissions made before ' 'January 2004', @@ -53,7 +48,6 @@ }, 'http://creativecommons.org/licenses/by/3.0/': { - 'uri': 'http://creativecommons.org/licenses/by/3.0/', 'label': 'Creative Commons Attribution license', 'order': 2, 'is_current': False, @@ -61,7 +55,6 @@ }, 'http://creativecommons.org/licenses/by-nc-sa/3.0/': { - 'uri': 'http://creativecommons.org/licenses/by-nc-sa/3.0/', 'label': 'Creative Commons Attribution-Noncommercial-ShareAlike ' 'license', 'order': 3, @@ -69,7 +62,6 @@ 'icon_uri': f'{LICENSE_ICON_BASE_URI}/by-nc-sa-3.0.png' }, 'http://creativecommons.org/licenses/publicdomain/': { - 'uri': 'http://creativecommons.org/licenses/publicdomain/', 'label': 'Creative Commons Public Domain Declaration', 'note': '(Suitable for US government employees, for example)', 'order': 4, From 2aa4211b96d0d4b6754ed1864f44aa41c7caa609 Mon Sep 17 00:00:00 2001 From: Martin Lessmeister Date: Thu, 17 May 2018 09:01:26 -0400 Subject: [PATCH 6/6] minor --- arxiv/license.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arxiv/license.py b/arxiv/license.py index 81db3582..9a4e9c59 100644 --- a/arxiv/license.py +++ b/arxiv/license.py @@ -73,7 +73,7 @@ ASSUMED_LICENSE = LICENSES['http://arxiv.org/licenses/assumed-1991-2003/'] -# Historical license to updated/current license (old: new) +# Historical license to updated/current license (old URI: new URI) TRANSLATED_LICENSES = { 'http://creativecommons.org/licenses/by/3.0/': 'http://creativecommons.org/licenses/by/4.0/',