forked from nih-sparc/sparc.client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_pennsieve_api.py
60 lines (48 loc) · 1.62 KB
/
test_pennsieve_api.py
1
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
51
52
53
54
55
56
57
58
59
60
import json
import pytest
import requests
import responses
from requests.exceptions import HTTPError
from sparc.client.services import PennsieveService
@responses.activate
def test_register_responses():
responses.add(
method=responses.GET,
url="http://api.pennsieve.io/datasets/",
content_type="application/json",
json={"key": "value"},
status=200,
)
responses.add(
method=responses.POST,
url="http://api.pennsieve.io/datasets/1/versions/1/files/download-manifest",
content_type="application/json",
json={"key2": "value2"},
status=200,
)
responses.add(
method=responses.PUT,
url="http://api.pennsieve.io/whatever",
content_type="application/json",
json={"key3": "value3"},
status=200,
)
responses.add(
method=responses.DELETE,
url="http://api.pennsieve.io/whatever",
content_type="application/json",
json={"key4": "value4"},
status=200,
)
p = PennsieveService(config={"pennsieve_profile_name": "test"}, connect=False)
resp = p.get("http://api.pennsieve.io/datasets/")
assert resp == {"key": "value"}
resp = p.post(
"http://api.pennsieve.io/datasets/1/versions/1/files/download-manifest",
json=json.dumps({"datasetId": 1}),
)
assert resp == {"key2": "value2"}
resp = p.put("http://api.pennsieve.io/whatever", json=json.dumps({"datasetId": 0}))
assert resp == {"key3": "value3"}
resp = p.delete("http://api.pennsieve.io/whatever", json=json.dumps({"datasetId": 0}))
assert resp == {"key4": "value4"}