reuse hosts definition in Zenodo tests
MODIFY
repo2docker/contentproviders/zenodo.py
repo2docker/contentproviders/zenodo.py
@@ -14,8 +14,6 @@ from ..utils import copytree, deep_get
class Zenodo(DoiProvider):
"""Provide contents of a Zenodo deposit."""
- def detect(self, doi, ref=None, extra_args=None):
- """Trigger this provider for things that resolve to a Zenodo/Invenio record"""
# 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)
@@ -41,9 +39,11 @@ class Zenodo(DoiProvider):
},
]
+ def detect(self, doi, ref=None, extra_args=None):
+ """Trigger this provider for things that resolve to a Zenodo/Invenio record"""
url = self.doi2url(doi)
- for host in hosts:
+ for host in self.hosts:
if any([url.startswith(s) for s in host["hostname"]]):
self.record_id = url.rsplit("/", maxsplit=1)[1]
return {"record": self.record_id, "host": host}

MODIFY
tests/unit/contentproviders/test_zenodo.py
tests/unit/contentproviders/test_zenodo.py
@@ -28,17 +28,7 @@ test_hosts = [
"10.5281/zenodo.3232985",
"https://doi.org/10.5281/zenodo.3232985",
],
- {
- "host": {
- "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",
- },
- "record": "3232985",
- },
+ {"host": Zenodo.hosts[0], "record": "3232985"},
),
(
[
@@ -46,20 +36,7 @@ test_hosts = [
"10.22002/d1.1235",
"https://doi.org/10.22002/d1.1235",
],
- {
- "host": {
- "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",
- },
- "record": "1235",
- },
+ {"host": Zenodo.hosts[1], "record": "1235"},
),
]
@@ -122,20 +99,7 @@ def test_fetch_software_from_github_archive():
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
zen = Zenodo()
- spec = {
- "host": {
- "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",
- },
- "record": "1234",
- }
+ spec = {"host": Zenodo.hosts[0], "record": "1234"}
with TemporaryDirectory() as d:
output = []
@@ -176,20 +140,7 @@ def test_fetch_software():
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
with TemporaryDirectory() as d:
zen = Zenodo()
- spec = spec = {
- "host": {
- "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",
- },
- "record": "1234",
- }
+ spec = spec = {"host": Zenodo.hosts[0], "record": "1234"}
output = []
for l in zen.fetch(spec, d):
output.append(l)
@@ -230,20 +181,7 @@ def test_fetch_data():
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
with TemporaryDirectory() as d:
zen = Zenodo()
- spec = {
- "host": {
- "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",
- },
- "record": "1234",
- }
+ spec = {"host": Zenodo.hosts[0], "record": "1234"}
output = []
for l in zen.fetch(spec, d):
output.append(l)

reuse hosts definition in Zenodo tests