initialize hosts as instance variable

pull/788/head
Daniel Nüst 2019-09-08 21:39:07 +02:00
rodzic e6cd4b19d9
commit b2b6030492
4 zmienionych plików z 53 dodań i 49 usunięć

Wyświetl plik

@ -23,19 +23,20 @@ class Figshare(DoiProvider):
- https://figshare.com/articles/binder-examples_requirements/9784088 (only one zipfile, no DOI)
"""
hosts = [
{
"hostname": [
"https://figshare.com/articles/",
"http://figshare.com/articles/",
"https://figshare.com/account/articles/",
],
"api": "https://api.figshare.com/v2/articles/",
"filepath": "files",
"filename": "name",
"download": "download_url",
}
]
def __init__(self):
self.hosts = [
{
"hostname": [
"https://figshare.com/articles/",
"http://figshare.com/articles/",
"https://figshare.com/account/articles/",
],
"api": "https://api.figshare.com/v2/articles/",
"filepath": "files",
"filename": "name",
"download": "download_url",
}
]
url_regex = re.compile(r"(.*)/articles/([^/]+)/(\d+)(/\d)?")

Wyświetl plik

@ -14,30 +14,31 @@ from ..utils import copytree, deep_get
class Zenodo(DoiProvider):
"""Provide contents of a Zenodo deposit."""
# We need the hostname (url where records are), api url (for metadata),
# filepath (path to files in metadata), filename (path to filename in
# metadata), download (path to file download URL), and type (path to item type in metadata)
hosts = [
{
"hostname": ["https://zenodo.org/record/", "http://zenodo.org/record/"],
"api": "https://zenodo.org/api/records/",
"filepath": "files",
"filename": "filename",
"download": "links.download",
"type": "metadata.upload_type",
},
{
"hostname": [
"https://data.caltech.edu/records/",
"http://data.caltech.edu/records/",
],
"api": "https://data.caltech.edu/api/record/",
"filepath": "metadata.electronic_location_and_access",
"filename": "electronic_name.0",
"download": "uniform_resource_identifier",
"type": "metadata.resourceType.resourceTypeGeneral",
},
]
def __init__(self):
# We need the hostname (url where records are), api url (for metadata),
# filepath (path to files in metadata), filename (path to filename in
# metadata), download (path to file download URL), and type (path to item type in metadata)
self.hosts = [
{
"hostname": ["https://zenodo.org/record/", "http://zenodo.org/record/"],
"api": "https://zenodo.org/api/records/",
"filepath": "files",
"filename": "filename",
"download": "links.download",
"type": "metadata.upload_type",
},
{
"hostname": [
"https://data.caltech.edu/records/",
"http://data.caltech.edu/records/",
],
"api": "https://data.caltech.edu/api/record/",
"filepath": "metadata.electronic_location_and_access",
"filename": "electronic_name.0",
"download": "uniform_resource_identifier",
"type": "metadata.resourceType.resourceTypeGeneral",
},
]
def detect(self, doi, ref=None, extra_args=None):
"""Trigger this provider for things that resolve to a Zenodo/Invenio record"""

Wyświetl plik

@ -20,31 +20,32 @@ def test_content_id():
assert fig.content_id == "9782777"
test_fig = Figshare()
test_dois_links = [
("10.6084/m9.figshare.9782777", {"host": Figshare.hosts[0], "article": "9782777"}),
("10.6084/m9.figshare.9782777", {"host": test_fig.hosts[0], "article": "9782777"}),
(
"10.6084/m9.figshare.9782777.v1",
{"host": Figshare.hosts[0], "article": "9782777"},
{"host": test_fig.hosts[0], "article": "9782777"},
),
(
"https://doi.org/10.6084/m9.figshare.9782777",
{"host": Figshare.hosts[0], "article": "9782777"},
{"host": test_fig.hosts[0], "article": "9782777"},
),
(
"https://figshare.com/articles/title/97827771234",
{"host": Figshare.hosts[0], "article": "97827771234"},
{"host": test_fig.hosts[0], "article": "97827771234"},
),
(
"https://figshare.com/articles/title/9782777/1",
{"host": Figshare.hosts[0], "article": "9782777"},
{"host": test_fig.hosts[0], "article": "9782777"},
),
(
"https://figshare.com/articles/title/9782777/",
{"host": Figshare.hosts[0], "article": "9782777"},
{"host": test_fig.hosts[0], "article": "9782777"},
),
]
test_spec = {"host": Figshare.hosts[0], "article": "1234"}
test_spec = {"host": test_fig.hosts[0], "article": "1234"}
@pytest.mark.parametrize("test_input,expected", test_dois_links)

Wyświetl plik

@ -21,6 +21,7 @@ def test_content_id():
assert zen.content_id == "3232985"
test_zen = Zenodo()
test_hosts = [
(
[
@ -28,7 +29,7 @@ test_hosts = [
"10.5281/zenodo.3232985",
"https://doi.org/10.5281/zenodo.3232985",
],
{"host": Zenodo.hosts[0], "record": "3232985"},
{"host": test_zen.hosts[0], "record": "3232985"},
),
(
[
@ -36,7 +37,7 @@ test_hosts = [
"10.22002/d1.1235",
"https://doi.org/10.22002/d1.1235",
],
{"host": Zenodo.hosts[1], "record": "1235"},
{"host": test_zen.hosts[1], "record": "1235"},
),
]
@ -99,7 +100,7 @@ def test_fetch_software_from_github_archive():
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
zen = Zenodo()
spec = {"host": Zenodo.hosts[0], "record": "1234"}
spec = {"host": test_zen.hosts[0], "record": "1234"}
with TemporaryDirectory() as d:
output = []
@ -140,7 +141,7 @@ def test_fetch_software():
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
with TemporaryDirectory() as d:
zen = Zenodo()
spec = spec = {"host": Zenodo.hosts[0], "record": "1234"}
spec = spec = {"host": test_zen.hosts[0], "record": "1234"}
output = []
for l in zen.fetch(spec, d):
output.append(l)
@ -181,7 +182,7 @@ def test_fetch_data():
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
with TemporaryDirectory() as d:
zen = Zenodo()
spec = {"host": Zenodo.hosts[0], "record": "1234"}
spec = {"host": test_zen.hosts[0], "record": "1234"}
output = []
for l in zen.fetch(spec, d):
output.append(l)