Skip to content

Commit cd28c4e

Browse files
committed
sty: run black on tests file
1 parent 2487a9a commit cd28c4e

File tree

1 file changed

+48
-43
lines changed

1 file changed

+48
-43
lines changed

test/testGetPost.py

+48-43
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
from glob import glob
88

99
# 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")
1313

1414
# 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")
1717

1818

1919
# url for GET
@@ -30,14 +30,14 @@ def getRequest(post_resp, url):
3030

3131

3232
# MAIN ######
33-
header = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
33+
header = {"content-type": "application/json", "Accept-Charset": "UTF-8"}
3434
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>")
3636
numOfTestData = 84
3737
urlBold = "http://0.0.0.0:80/api/v1/bold"
3838
urlT1w = "http://0.0.0.0:80/api/v1/T1w"
3939
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?{}"
4141
codeForInvalid = 422
4242

4343

@@ -51,16 +51,16 @@ def test_00_GETAllData(self):
5151
inputData = json.load(fp)
5252

5353
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+
)
5657
self.assertTrue(postResponse.raise_for_status() is None)
5758

5859
# GET request
5960
# print requests.get(urlT1w)
6061
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"])
6464

6565
# Testing Bold ############
6666
def test_01_ConnectionStatus(self):
@@ -72,16 +72,17 @@ def test_01_ConnectionStatus(self):
7272

7373
# POST request
7474
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+
)
7677

7778
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())
7980
self.assertTrue(post_resp.raise_for_status() is None)
8081

8182
# GET request
8283
get_resp = requests.get(getURL(post_resp, urlBold))
8384
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())
8586
self.assertTrue(get_resp.raise_for_status() is None)
8687

8788
def test_02_MissingFieldInput(self):
@@ -90,8 +91,8 @@ def test_02_MissingFieldInput(self):
9091
input_data = json.load(fp)
9192
# POST request
9293
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+
)
9596
# print post_resp.status_code
9697
self.assertTrue(post_resp.status_code == codeForInvalid)
9798

@@ -105,16 +106,17 @@ def test_03_ConnectionStatus(self):
105106
# print input_data
106107
# POST request
107108
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+
)
109111

110-
log.debug('Response: %s', post_resp.json())
112+
log.debug("Response: %s", post_resp.json())
111113
if post_resp.raise_for_status() is not None:
112114
self.assertTrue(post_resp.raise_for_status() is None)
113115

114116
# GET request
115117
get_resp = requests.get(getURL(post_resp, urlT1w))
116118
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())
118120
self.assertTrue(get_resp.raise_for_status() is None)
119121

120122
def test_04_MissingFieldInput(self):
@@ -123,8 +125,8 @@ def test_04_MissingFieldInput(self):
123125
input_data = json.load(fp)
124126
# POST request
125127
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+
)
128130
# print post_resp.status_code
129131
self.assertTrue(post_resp.status_code == codeForInvalid)
130132

@@ -135,8 +137,8 @@ def test_05_boldDataToT1wEndPoint(self):
135137
input_data = json.load(fp)
136138
# POST request
137139
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+
)
140142
self.assertTrue(post_resp.status_code == codeForInvalid)
141143

142144
def test_06_T1wDataToBoldEndPoint(self):
@@ -145,8 +147,8 @@ def test_06_T1wDataToBoldEndPoint(self):
145147
input_data = json.load(fp)
146148
# POST request
147149
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+
)
150152
self.assertTrue(post_resp.status_code == codeForInvalid)
151153

152154
def test_07_T1wDataValid(self):
@@ -155,8 +157,8 @@ def test_07_T1wDataValid(self):
155157
input_data = json.load(fp)
156158
# 2. POST request
157159
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+
)
160162

161163
# 3. GET request
162164
queried_data = getRequest(post_resp, urlT1w)
@@ -174,8 +176,8 @@ def test_08_boldDataValid(self):
174176

175177
# 2. POST request
176178
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+
)
179181
self.assertTrue(post_resp.raise_for_status() is None)
180182

181183
# 3. GET request
@@ -190,8 +192,9 @@ def test_08_boldDataValid(self):
190192
def test_09_failedAuth(self):
191193
with open(glob(boldPattern)[0]) as fp:
192194
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+
)
195198
self.assertTrue(postResponse.status_code == 401) # ****************
196199

197200
def test_10_ratingDataValid(self):
@@ -201,24 +204,26 @@ def test_10_ratingDataValid(self):
201204

202205
# 2. POST request
203206
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+
)
206209
self.assertTrue(post_resp.raise_for_status() is None)
207210

208211
# retrive counts of ratings we just submitted
209212
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,
212217
)
213218
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)
219224

220225

221-
if __name__ == '__main__':
226+
if __name__ == "__main__":
222227
logging.basicConfig(stream=sys.stderr)
223228
logging.getLogger("mriqcwebapi").setLevel(logging.DEBUG)
224229

0 commit comments

Comments
 (0)