Skip to content

Commit ebdd121

Browse files
committed
Update zenodo mocks
1 parent 74a94cf commit ebdd121

File tree

1 file changed

+58
-10
lines changed

1 file changed

+58
-10
lines changed

tests/unit/contentproviders/test_zenodo.py

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,31 @@ def test_fetch_software_from_github_archive(requests_mock):
9292
# we "fetch" a local ZIP file to simulate a Zenodo record created from a
9393
# GitHub repository via the Zenodo-GitHub integration
9494
with zenodo_archive() as zen_path:
95-
mock_response = {
95+
mock_record = {
9696
"files": [
9797
{
9898
"filename": "some_dir/afake.zip",
99-
"links": {"download": f"file://{zen_path}"},
10099
}
101100
],
101+
"links": {
102+
"files": "https://zenodo.org/api/records/1234/files",
103+
},
102104
"metadata": {"upload_type": "other"},
103105
}
104-
requests_mock.get("https://zenodo.org/api/records/1234", json=mock_response)
106+
requests_mock.get("https://zenodo.org/api/records/1234", json=mock_record)
107+
108+
mock_record_files = {
109+
"entries": [
110+
{
111+
"key": "some_dir/afake.zip",
112+
"links": {"content": f"file://{zen_path}"},
113+
}
114+
],
115+
}
116+
requests_mock.get(
117+
"https://zenodo.org/api/records/1234/files", json=mock_record_files
118+
)
119+
105120
requests_mock.get(f"file://{zen_path}", content=open(zen_path, "rb").read())
106121

107122
zen = Zenodo()
@@ -121,18 +136,33 @@ def test_fetch_software(requests_mock):
121136
# we "fetch" a local ZIP file to simulate a Zenodo software record with a
122137
# ZIP file in it
123138
with zenodo_archive() as zen_path:
124-
mock_response = {
139+
mock_record = {
125140
"files": [
126141
{
127142
# this is the difference to the GitHub generated one,
128143
# the ZIP file isn't in a directory
129144
"filename": "afake.zip",
130-
"links": {"download": f"file://{zen_path}"},
131145
}
132146
],
147+
"links": {
148+
"files": "https://zenodo.org/api/records/1234/files",
149+
},
133150
"metadata": {"upload_type": "software"},
134151
}
135-
requests_mock.get("https://zenodo.org/api/records/1234", json=mock_response)
152+
requests_mock.get("https://zenodo.org/api/records/1234", json=mock_record)
153+
154+
mock_record_files = {
155+
"entries": [
156+
{
157+
"key": "afake.zip",
158+
"links": {"content": f"file://{zen_path}"},
159+
}
160+
],
161+
}
162+
requests_mock.get(
163+
"https://zenodo.org/api/records/1234/files", json=mock_record_files
164+
)
165+
136166
requests_mock.get(f"file://{zen_path}", content=open(zen_path, "rb").read())
137167

138168
with TemporaryDirectory() as d:
@@ -151,20 +181,38 @@ def test_fetch_data(requests_mock):
151181
# we "fetch" a local ZIP file to simulate a Zenodo data record
152182
with zenodo_archive() as a_zen_path:
153183
with zenodo_archive() as b_zen_path:
154-
mock_response = {
184+
mock_record = {
155185
"files": [
156186
{
157187
"filename": "afake.zip",
158-
"links": {"download": f"file://{a_zen_path}"},
159188
},
160189
{
161190
"filename": "bfake.zip",
162-
"links": {"download": f"file://{b_zen_path}"},
163191
},
164192
],
193+
"links": {
194+
"files": "https://zenodo.org/api/records/1234/files",
195+
},
165196
"metadata": {"upload_type": "data"},
166197
}
167-
requests_mock.get("https://zenodo.org/api/records/1234", json=mock_response)
198+
requests_mock.get("https://zenodo.org/api/records/1234", json=mock_record)
199+
200+
mock_record_files = {
201+
"entries": [
202+
{
203+
"key": "afake.zip",
204+
"links": {"content": f"file://{a_zen_path}"},
205+
},
206+
{
207+
"key": "bfake.zip",
208+
"links": {"content": f"file://{b_zen_path}"},
209+
},
210+
],
211+
}
212+
requests_mock.get(
213+
"https://zenodo.org/api/records/1234/files", json=mock_record_files
214+
)
215+
168216
requests_mock.get(
169217
f"file://{a_zen_path}", content=open(a_zen_path, "rb").read()
170218
)

0 commit comments

Comments
 (0)