def add_license(self, url=None, license=None, material=None, imposing=None): """Add license. :param url: url for the description of the license :type url: string :param license: license type :type license: string :param material: material type :type material: string :param imposing: imposing type :type imposing: string """ hep_license = {} try: license_from_url = get_license_from_url(url) if license_from_url is not None: license = license_from_url except ValueError: pass for key in ('url', 'license', 'material', 'imposing'): if locals()[key] is not None: hep_license[key] = locals()[key] self._append_to('license', hep_license)
def test_get_license_from_url_handles_arxiv(): expected = 'arXiv nonexclusive-distrib 1.0' url = 'http://arxiv.org/licenses/nonexclusive-distrib/1.0/' assert utils.get_license_from_url(url) == expected
def test_get_license_from_url_handles_CC_public_domain_no_match(): url = 'http://creativecommons.org/publicdomain/nomatch' assert utils.get_license_from_url(url) == 'public domain'
def test_get_license_from_url_handles_CC_public_domain(): url = 'http://creativecommons.org/publicdomain/zero/1.0/' assert utils.get_license_from_url(url) == 'CC0 1.0'
def test_get_license_from_url_handles_CC(): url = 'http://creativecommons.org/licenses/by-nc/4.0/' assert utils.get_license_from_url(url) == 'CC BY-NC 4.0'
def test_get_license_from_url_raises_when_unknown_url(): with pytest.raises(ValueError): utils.get_license_from_url('http://www.example.com')
def test_get_license_from_url_handles_none(): assert utils.get_license_from_url(None) is None