-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-v1.py
67 lines (54 loc) · 2.05 KB
/
test-v1.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
61
62
63
64
65
66
67
import os
import time
import requests
from retrying import retry
from requests.structures import CaseInsensitiveDict
url = os.environ['CTS_API_URL'] + 'v1/'
headers = CaseInsensitiveDict()
if 'API_KEY' in os.environ:
headers['x-api-key'] = os.environ['API_KEY']
else:
headers['Origin'] = os.environ['TESTING_ORIGIN']
headers['Content-Type'] = 'application/json'
@retry(stop_max_attempt_number=5, wait_random_min=1000, wait_random_max=5000)
def execute_get(url, headers, should_fail):
response = requests.get(url, headers=headers)
if response.status_code != 200:
if should_fail:
print('GET %s failed (was supposed to).' % url)
else:
print(response.content)
raise Exception('GET %s Failed with Code %s' % (url, str(response.status_code)))
else:
print('GET %s succeeded.' % url)
@retry(stop_max_attempt_number=5, wait_random_min=1000, wait_random_max=5000)
def execute_post(url, headers, body, should_fail):
response = requests.post(url, headers=headers, json=body)
if response.status_code != 200:
if should_fail:
print('POST %s failed (was supposed to).' % url)
else:
print(response.content)
raise Exception('POST %s Failed with Code %s' % (url, str(response.status_code)))
else:
print('POST %s succeeded.' % url)
# Test 1
execute_get(url + 'clinical-trials?include=nci_id', headers, False)
# Test 2
execute_get(url + 'terms?term_type=lead_org', headers, False)
# Test 3 (max of 200)
for i in range(0, 6):
size = (i * 10**i) + 1
execute_get(url + 'diseases?type=maintype&size=%s' % size, headers, size > 200)
# Test 4 (max of 200)
for i in range(0, 6):
size = (i * 10**i) + 1
execute_get(url + 'interventions?size=%s' % size, headers, size > 200)
# Test 5
for year in range(2016, 2022):
body = {
"sites.org_state_or_province": ["CA", "OR"],
"record_verification_date_gte": "%s-06-01" % year,
"include": ["nci_id"]
}
execute_post(url + 'clinical-trials', headers, body, False)