Skip to content

Commit b2b6030

Browse files
committed
initialize hosts as instance variable
1 parent e6cd4b1 commit b2b6030

File tree

4 files changed

+53
-49
lines changed

4 files changed

+53
-49
lines changed

repo2docker/contentproviders/figshare.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ class Figshare(DoiProvider):
2323
- https://figshare.com/articles/binder-examples_requirements/9784088 (only one zipfile, no DOI)
2424
"""
2525

26-
hosts = [
27-
{
28-
"hostname": [
29-
"https://figshare.com/articles/",
30-
"http://figshare.com/articles/",
31-
"https://figshare.com/account/articles/",
32-
],
33-
"api": "https://api.figshare.com/v2/articles/",
34-
"filepath": "files",
35-
"filename": "name",
36-
"download": "download_url",
37-
}
38-
]
26+
def __init__(self):
27+
self.hosts = [
28+
{
29+
"hostname": [
30+
"https://figshare.com/articles/",
31+
"http://figshare.com/articles/",
32+
"https://figshare.com/account/articles/",
33+
],
34+
"api": "https://api.figshare.com/v2/articles/",
35+
"filepath": "files",
36+
"filename": "name",
37+
"download": "download_url",
38+
}
39+
]
3940

4041
url_regex = re.compile(r"(.*)/articles/([^/]+)/(\d+)(/\d)?")
4142

repo2docker/contentproviders/zenodo.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,31 @@
1414
class Zenodo(DoiProvider):
1515
"""Provide contents of a Zenodo deposit."""
1616

17-
# We need the hostname (url where records are), api url (for metadata),
18-
# filepath (path to files in metadata), filename (path to filename in
19-
# metadata), download (path to file download URL), and type (path to item type in metadata)
20-
hosts = [
21-
{
22-
"hostname": ["https://zenodo.org/record/", "http://zenodo.org/record/"],
23-
"api": "https://zenodo.org/api/records/",
24-
"filepath": "files",
25-
"filename": "filename",
26-
"download": "links.download",
27-
"type": "metadata.upload_type",
28-
},
29-
{
30-
"hostname": [
31-
"https://data.caltech.edu/records/",
32-
"http://data.caltech.edu/records/",
33-
],
34-
"api": "https://data.caltech.edu/api/record/",
35-
"filepath": "metadata.electronic_location_and_access",
36-
"filename": "electronic_name.0",
37-
"download": "uniform_resource_identifier",
38-
"type": "metadata.resourceType.resourceTypeGeneral",
39-
},
40-
]
17+
def __init__(self):
18+
# We need the hostname (url where records are), api url (for metadata),
19+
# filepath (path to files in metadata), filename (path to filename in
20+
# metadata), download (path to file download URL), and type (path to item type in metadata)
21+
self.hosts = [
22+
{
23+
"hostname": ["https://zenodo.org/record/", "http://zenodo.org/record/"],
24+
"api": "https://zenodo.org/api/records/",
25+
"filepath": "files",
26+
"filename": "filename",
27+
"download": "links.download",
28+
"type": "metadata.upload_type",
29+
},
30+
{
31+
"hostname": [
32+
"https://data.caltech.edu/records/",
33+
"http://data.caltech.edu/records/",
34+
],
35+
"api": "https://data.caltech.edu/api/record/",
36+
"filepath": "metadata.electronic_location_and_access",
37+
"filename": "electronic_name.0",
38+
"download": "uniform_resource_identifier",
39+
"type": "metadata.resourceType.resourceTypeGeneral",
40+
},
41+
]
4142

4243
def detect(self, doi, ref=None, extra_args=None):
4344
"""Trigger this provider for things that resolve to a Zenodo/Invenio record"""

tests/unit/contentproviders/test_figshare.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,32 @@ def test_content_id():
2020
assert fig.content_id == "9782777"
2121

2222

23+
test_fig = Figshare()
2324
test_dois_links = [
24-
("10.6084/m9.figshare.9782777", {"host": Figshare.hosts[0], "article": "9782777"}),
25+
("10.6084/m9.figshare.9782777", {"host": test_fig.hosts[0], "article": "9782777"}),
2526
(
2627
"10.6084/m9.figshare.9782777.v1",
27-
{"host": Figshare.hosts[0], "article": "9782777"},
28+
{"host": test_fig.hosts[0], "article": "9782777"},
2829
),
2930
(
3031
"https://doi.org/10.6084/m9.figshare.9782777",
31-
{"host": Figshare.hosts[0], "article": "9782777"},
32+
{"host": test_fig.hosts[0], "article": "9782777"},
3233
),
3334
(
3435
"https://figshare.com/articles/title/97827771234",
35-
{"host": Figshare.hosts[0], "article": "97827771234"},
36+
{"host": test_fig.hosts[0], "article": "97827771234"},
3637
),
3738
(
3839
"https://figshare.com/articles/title/9782777/1",
39-
{"host": Figshare.hosts[0], "article": "9782777"},
40+
{"host": test_fig.hosts[0], "article": "9782777"},
4041
),
4142
(
4243
"https://figshare.com/articles/title/9782777/",
43-
{"host": Figshare.hosts[0], "article": "9782777"},
44+
{"host": test_fig.hosts[0], "article": "9782777"},
4445
),
4546
]
4647

47-
test_spec = {"host": Figshare.hosts[0], "article": "1234"}
48+
test_spec = {"host": test_fig.hosts[0], "article": "1234"}
4849

4950

5051
@pytest.mark.parametrize("test_input,expected", test_dois_links)

tests/unit/contentproviders/test_zenodo.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,23 @@ def test_content_id():
2121
assert zen.content_id == "3232985"
2222

2323

24+
test_zen = Zenodo()
2425
test_hosts = [
2526
(
2627
[
2728
"https://zenodo.org/record/3232985",
2829
"10.5281/zenodo.3232985",
2930
"https://doi.org/10.5281/zenodo.3232985",
3031
],
31-
{"host": Zenodo.hosts[0], "record": "3232985"},
32+
{"host": test_zen.hosts[0], "record": "3232985"},
3233
),
3334
(
3435
[
3536
"https://data.caltech.edu/records/1235",
3637
"10.22002/d1.1235",
3738
"https://doi.org/10.22002/d1.1235",
3839
],
39-
{"host": Zenodo.hosts[1], "record": "1235"},
40+
{"host": test_zen.hosts[1], "record": "1235"},
4041
),
4142
]
4243

@@ -99,7 +100,7 @@ def mock_urlopen(self, req):
99100

100101
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
101102
zen = Zenodo()
102-
spec = {"host": Zenodo.hosts[0], "record": "1234"}
103+
spec = {"host": test_zen.hosts[0], "record": "1234"}
103104

104105
with TemporaryDirectory() as d:
105106
output = []
@@ -140,7 +141,7 @@ def mock_urlopen(self, req):
140141
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
141142
with TemporaryDirectory() as d:
142143
zen = Zenodo()
143-
spec = spec = {"host": Zenodo.hosts[0], "record": "1234"}
144+
spec = spec = {"host": test_zen.hosts[0], "record": "1234"}
144145
output = []
145146
for l in zen.fetch(spec, d):
146147
output.append(l)
@@ -181,7 +182,7 @@ def mock_urlopen(self, req):
181182
with patch.object(Zenodo, "urlopen", new=mock_urlopen):
182183
with TemporaryDirectory() as d:
183184
zen = Zenodo()
184-
spec = {"host": Zenodo.hosts[0], "record": "1234"}
185+
spec = {"host": test_zen.hosts[0], "record": "1234"}
185186
output = []
186187
for l in zen.fetch(spec, d):
187188
output.append(l)

0 commit comments

Comments
 (0)