|
28 | 28 | expected=b'Hello, World!'
|
29 | 29 |
|
30 | 30 | deftest(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 |
| -ifcontent!=expected: |
34 |
| -print('ERROR:\'{0}\' !=\'{1}\''.format(content,expected)) |
| 31 | +globalstatus |
| 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 | +ifcontent!=expected: |
| 36 | +print('ERROR:\'{0}\' !=\'{1}\''.format(content,expected)) |
| 37 | +status=1 |
| 38 | +else: |
| 39 | +print('... passed.') |
| 40 | +exceptExceptionase: |
| 41 | +print('Caught Exception: {0}'.format(e)) |
35 | 42 | status=1
|
36 |
| -else: |
37 |
| -print('... passed.') |
38 | 43 |
|
39 | 44 | deftest_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 |
| -ifresp['status']!=expected: |
43 |
| -print('ERROR: response status ({0}) != 400'.format(resp['status'])) |
| 45 | +globalstatus |
| 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 | +ifresp['status']!=expected: |
| 50 | +print('ERROR: response status ({0}) != 400'.format(resp['status'])) |
| 51 | +status=1 |
| 52 | +else: |
| 53 | +print('... passed.') |
| 54 | +exceptExceptionase: |
| 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)
|
|