Newer
Older
#!/usr/bin/env python
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import requests
import numpy as np
from distutils.util import strtobool
from zenodoapi import ZenodoAPI
if __name__ == '__main__':
# Required arguments
parser = argparse.ArgumentParser(description="Upload new deposit entry to Zenodo")
parser.add_argument('--token', '-t', type=str,
dest='zenodo_token',
help='Personal access token to (sandbox)Zenodo')
parser.add_argument('--sandbox_zenodo', '-s', action='store',
type=lambda x: bool(strtobool(x)),
dest='sandbox_flag',
help='Set the Zenodo environment.'
'If True connects with Zenodo. If False with Sanbox Zenodo',
default=False)
args = parser.parse_args()
z = ZenodoAPI(access_token=args.zenodo_token,
sandbox=args.sandbox_flag # True for sandbox.zenodo.org !! False for zenodo.org
)
# Test that the you can communicate with (sandbox)zenodo - you have passed the correct token
parameters = {'access_token': z.access_token}
test_connection = requests.get(
f'{z.zenodo_api_url}/deposit/depositions',
params=parameters
)
np.testing.assert_equal(test_connection.status_code, 200)
# Test that you can create a new entry - then all the rest of the pipeline will work
new_entry = z.create_new_entry()
np.testing.assert_equal(new_entry.status_code, 201)
# Erase the un-submitted entry and test that the order has been passed correctly
entry_id = new_entry.json()['id']
erase_unsubmitted_entry = requests.delete(
f'{z.zenodo_api_url}/deposit/depositions/{entry_id}',
params=parameters
)
np.testing.assert_equal(erase_unsubmitted_entry.status_code, 204)