Skip to content

Commit 7132a99

Browse files
committed
Acceptance Test Improvements
- Make the tests properly catch errors - Report whether there were actual failures instead of silently passing
1 parent c3c69ad commit 7132a99

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

libs/network/test/httplib_acceptance.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,32 @@
2828
expected = b'Hello, World!'
2929

3030
def test(url, method, expected, headers={}, body=''):
31-
resp, content = client.request(url, method, headers=headers, body=body)
32-
print('Request: {method} {url} body=\'{body}\''.format(method=method, url=url, body=body)),
33-
if content != expected:
34-
print('ERROR: \'{0}\' != \'{1}\''.format(content, expected))
31+
global status
32+
try:
33+
print('Request: {method} {url} body=\'{body}\''.format(method=method, url=url, body=body)),
34+
resp, content = client.request(url, method, headers=headers, body=body)
35+
if content != expected:
36+
print('ERROR: \'{0}\' != \'{1}\''.format(content, expected))
37+
status = 1
38+
else:
39+
print('... passed.')
40+
except Exception as e:
41+
print('Caught Exception: {0}'.format(e))
3542
status = 1
36-
else:
37-
print('... passed.')
3843

3944
def test_status(url, method, expected, headers={}, body=''):
40-
resp, content = client.request('http://localhost:8000/', 'PUT', body='')
41-
print('Request: {method} {url} body=\'{body}\''.format(method=method, url=url, body=body)),
42-
if resp['status'] != expected:
43-
print('ERROR: response status ({0}) != 400'.format(resp['status']))
45+
global status
46+
try:
47+
print('Request: {method} {url} body=\'{body}\''.format(method=method, url=url, body=body)),
48+
resp, content = client.request('http://localhost:8000/', 'PUT', body='')
49+
if resp['status'] != expected:
50+
print('ERROR: response status ({0}) != 400'.format(resp['status']))
51+
status = 1
52+
else:
53+
print('... passed.')
54+
except Exception as e:
55+
print('Caught Exception: {0}'.format(e))
4456
status = 1
45-
else:
46-
print('... passed.')
4757

4858
url = 'http://localhost:8000/'
4959
test(url, 'GET', expected)

0 commit comments

Comments
 (0)