|
28 | 28 | expected = b'Hello, World!'
|
29 | 29 |
|
30 | 30 | 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)) |
35 | 42 | status = 1
|
36 |
| - else: |
37 |
| - print('... passed.') |
38 | 43 |
|
39 | 44 | 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)) |
44 | 56 | status = 1
|
45 |
| - else: |
46 |
| - print('... passed.') |
47 | 57 |
|
48 | 58 | url = 'http://localhost:8000/'
|
49 | 59 | test(url, 'GET', expected)
|
|
0 commit comments