7
7
from glob import glob
8
8
9
9
# test data directory
10
- boldPattern = os .path .join (' test/bold/validData' , ' *.json' )
11
- T1wPattern = os .path .join (' test/T1w/validData' , ' *.json' )
12
- ratingPattern = os .path .join (' test/rating/validData' , ' *.json' )
10
+ boldPattern = os .path .join (" test/bold/validData" , " *.json" )
11
+ T1wPattern = os .path .join (" test/T1w/validData" , " *.json" )
12
+ ratingPattern = os .path .join (" test/rating/validData" , " *.json" )
13
13
14
14
# missing field data directory
15
- boldMissingPattern = os .path .join (' test/bold/missingField' , ' *.json' )
16
- T1wMissingPattern = os .path .join (' test/T1w/missingField' , ' *.json' )
15
+ boldMissingPattern = os .path .join (" test/bold/missingField" , " *.json" )
16
+ T1wMissingPattern = os .path .join (" test/T1w/missingField" , " *.json" )
17
17
18
18
19
19
# url for GET
@@ -30,14 +30,14 @@ def getRequest(post_resp, url):
30
30
31
31
32
32
# MAIN ######
33
- header = {' content-type' : ' application/json' , ' Accept-Charset' : ' UTF-8' }
33
+ header = {" content-type" : " application/json" , " Accept-Charset" : " UTF-8" }
34
34
authenticated_header = header .copy ()
35
- authenticated_header [' Authorization' ] = os .environ .get (' API_TOKEN' , ' <secret_token>' )
35
+ authenticated_header [" Authorization" ] = os .environ .get (" API_TOKEN" , " <secret_token>" )
36
36
numOfTestData = 84
37
37
urlBold = "http://0.0.0.0:80/api/v1/bold"
38
38
urlT1w = "http://0.0.0.0:80/api/v1/T1w"
39
39
urlRating = "http://0.0.0.0:80/api/v1/rating"
40
- urlRatingCounts = ' http://0.0.0.0:80/api/v1/rating_counts?{}'
40
+ urlRatingCounts = " http://0.0.0.0:80/api/v1/rating_counts?{}"
41
41
codeForInvalid = 422
42
42
43
43
@@ -51,16 +51,16 @@ def test_00_GETAllData(self):
51
51
inputData = json .load (fp )
52
52
53
53
input_count += 1 # POST request
54
- postResponse = requests .post (urlT1w , data = json .dumps (inputData ),
55
- headers = authenticated_header )
54
+ postResponse = requests .post (
55
+ urlT1w , data = json .dumps (inputData ), headers = authenticated_header
56
+ )
56
57
self .assertTrue (postResponse .raise_for_status () is None )
57
58
58
59
# GET request
59
60
# print requests.get(urlT1w)
60
61
get_resp = requests .get (urlT1w ).json ()
61
- log .debug ("total: %d (input_count=%d)" , get_resp ['_meta' ]['total' ],
62
- input_count )
63
- self .assertTrue (input_count == get_resp ['_meta' ]['total' ])
62
+ log .debug ("total: %d (input_count=%d)" , get_resp ["_meta" ]["total" ], input_count )
63
+ self .assertTrue (input_count == get_resp ["_meta" ]["total" ])
64
64
65
65
# Testing Bold ############
66
66
def test_01_ConnectionStatus (self ):
@@ -72,16 +72,17 @@ def test_01_ConnectionStatus(self):
72
72
73
73
# POST request
74
74
post_resp = requests .post (
75
- urlBold , data = json .dumps (input_data ), headers = authenticated_header )
75
+ urlBold , data = json .dumps (input_data ), headers = authenticated_header
76
+ )
76
77
77
78
if post_resp .raise_for_status () is not None :
78
- log .debug (' Response: %s' , post_resp .json ())
79
+ log .debug (" Response: %s" , post_resp .json ())
79
80
self .assertTrue (post_resp .raise_for_status () is None )
80
81
81
82
# GET request
82
83
get_resp = requests .get (getURL (post_resp , urlBold ))
83
84
if get_resp .raise_for_status () is not None :
84
- log .debug (' Response: %s' , get_resp .json ())
85
+ log .debug (" Response: %s" , get_resp .json ())
85
86
self .assertTrue (get_resp .raise_for_status () is None )
86
87
87
88
def test_02_MissingFieldInput (self ):
@@ -90,8 +91,8 @@ def test_02_MissingFieldInput(self):
90
91
input_data = json .load (fp )
91
92
# POST request
92
93
post_resp = requests .post (
93
- urlBold , data = json .dumps (input_data ),
94
- headers = authenticated_header )
94
+ urlBold , data = json .dumps (input_data ), headers = authenticated_header
95
+ )
95
96
# print post_resp.status_code
96
97
self .assertTrue (post_resp .status_code == codeForInvalid )
97
98
@@ -105,16 +106,17 @@ def test_03_ConnectionStatus(self):
105
106
# print input_data
106
107
# POST request
107
108
post_resp = requests .post (
108
- urlT1w , data = json .dumps (input_data ), headers = authenticated_header )
109
+ urlT1w , data = json .dumps (input_data ), headers = authenticated_header
110
+ )
109
111
110
- log .debug (' Response: %s' , post_resp .json ())
112
+ log .debug (" Response: %s" , post_resp .json ())
111
113
if post_resp .raise_for_status () is not None :
112
114
self .assertTrue (post_resp .raise_for_status () is None )
113
115
114
116
# GET request
115
117
get_resp = requests .get (getURL (post_resp , urlT1w ))
116
118
if get_resp .raise_for_status () is not None :
117
- log .debug (' Response: %s' , get_resp .json ())
119
+ log .debug (" Response: %s" , get_resp .json ())
118
120
self .assertTrue (get_resp .raise_for_status () is None )
119
121
120
122
def test_04_MissingFieldInput (self ):
@@ -123,8 +125,8 @@ def test_04_MissingFieldInput(self):
123
125
input_data = json .load (fp )
124
126
# POST request
125
127
post_resp = requests .post (
126
- urlT1w , data = json .dumps (input_data ),
127
- headers = authenticated_header )
128
+ urlT1w , data = json .dumps (input_data ), headers = authenticated_header
129
+ )
128
130
# print post_resp.status_code
129
131
self .assertTrue (post_resp .status_code == codeForInvalid )
130
132
@@ -135,8 +137,8 @@ def test_05_boldDataToT1wEndPoint(self):
135
137
input_data = json .load (fp )
136
138
# POST request
137
139
post_resp = requests .post (
138
- urlT1w , data = json .dumps (input_data ),
139
- headers = authenticated_header )
140
+ urlT1w , data = json .dumps (input_data ), headers = authenticated_header
141
+ )
140
142
self .assertTrue (post_resp .status_code == codeForInvalid )
141
143
142
144
def test_06_T1wDataToBoldEndPoint (self ):
@@ -145,8 +147,8 @@ def test_06_T1wDataToBoldEndPoint(self):
145
147
input_data = json .load (fp )
146
148
# POST request
147
149
post_resp = requests .post (
148
- urlBold , data = json .dumps (input_data ),
149
- headers = authenticated_header )
150
+ urlBold , data = json .dumps (input_data ), headers = authenticated_header
151
+ )
150
152
self .assertTrue (post_resp .status_code == codeForInvalid )
151
153
152
154
def test_07_T1wDataValid (self ):
@@ -155,8 +157,8 @@ def test_07_T1wDataValid(self):
155
157
input_data = json .load (fp )
156
158
# 2. POST request
157
159
post_resp = requests .post (
158
- urlT1w , data = json .dumps (input_data ),
159
- headers = authenticated_header )
160
+ urlT1w , data = json .dumps (input_data ), headers = authenticated_header
161
+ )
160
162
161
163
# 3. GET request
162
164
queried_data = getRequest (post_resp , urlT1w )
@@ -174,8 +176,8 @@ def test_08_boldDataValid(self):
174
176
175
177
# 2. POST request
176
178
post_resp = requests .post (
177
- urlBold , data = json .dumps (input_data ),
178
- headers = authenticated_header )
179
+ urlBold , data = json .dumps (input_data ), headers = authenticated_header
180
+ )
179
181
self .assertTrue (post_resp .raise_for_status () is None )
180
182
181
183
# 3. GET request
@@ -190,8 +192,9 @@ def test_08_boldDataValid(self):
190
192
def test_09_failedAuth (self ):
191
193
with open (glob (boldPattern )[0 ]) as fp :
192
194
inputData = json .load (fp )
193
- postResponse = requests .post (urlBold , data = json .dumps (inputData ),
194
- headers = header )
195
+ postResponse = requests .post (
196
+ urlBold , data = json .dumps (inputData ), headers = header
197
+ )
195
198
self .assertTrue (postResponse .status_code == 401 ) # ****************
196
199
197
200
def test_10_ratingDataValid (self ):
@@ -201,24 +204,26 @@ def test_10_ratingDataValid(self):
201
204
202
205
# 2. POST request
203
206
post_resp = requests .post (
204
- urlRating , data = json .dumps (input_data ),
205
- headers = authenticated_header )
207
+ urlRating , data = json .dumps (input_data ), headers = authenticated_header
208
+ )
206
209
self .assertTrue (post_resp .raise_for_status () is None )
207
210
208
211
# retrive counts of ratings we just submitted
209
212
get_resp = requests .get (
210
- urlRatingCounts .format ('aggregate={"$value":"57cd35190da3c813a3c3dadccd8a4ad7"}' ),
211
- headers = authenticated_header
213
+ urlRatingCounts .format (
214
+ 'aggregate={"$value":"57cd35190da3c813a3c3dadccd8a4ad7"}'
215
+ ),
216
+ headers = authenticated_header ,
212
217
)
213
218
data = get_resp .json ()
214
- for elem in data [' _items' ]:
215
- if elem [' _id' ] == "good" :
216
- self .assertTrue (elem [' count' ] == 3 )
217
- if elem [' _id' ] == "bad" :
218
- self .assertTrue (elem [' count' ] == 1 )
219
+ for elem in data [" _items" ]:
220
+ if elem [" _id" ] == "good" :
221
+ self .assertTrue (elem [" count" ] == 3 )
222
+ if elem [" _id" ] == "bad" :
223
+ self .assertTrue (elem [" count" ] == 1 )
219
224
220
225
221
- if __name__ == ' __main__' :
226
+ if __name__ == " __main__" :
222
227
logging .basicConfig (stream = sys .stderr )
223
228
logging .getLogger ("mriqcwebapi" ).setLevel (logging .DEBUG )
224
229
0 commit comments