- Timestamp:
- Dec 1, 2019, 10:14:18 AM (15 months ago)
- Branches:
- asyncio, master, proxy-ticket
- Children:
- 8335f8c
- Parents:
- a4e136a
- Location:
- test
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
test/.gitignore
ra4e136a r096859f 6 6 authority/client/uid 7 7 authority/tofu.db 8 /__pycache__/ 8 9 9 10 # generated X.509 data -
test/https-test-client.py
ra4e136a r096859f 77 77 def __repr__(self): 78 78 return (f'{self.__class__.__name__!s}(path={self.path!r}, ' 79 f'method={self.method!r}), headers={self.headers!r}, ' 80 f'expect={self.expect!r}') 79 f'method={self.method!r}, headers={self.headers!r}, ' 80 f'expect={self.expect!r})') 81 82 def _check_body(self, body): 83 """ 84 >>> r1 = TestRequest(path='/test.txt', method='GET', headers={}, expect={'status': 200, 'body': {'exactly': 'test\\n'}}) 85 >>> r1._check_body('test\\n') 86 >>> r1._check_body('xyz\\n') 87 Traceback (most recent call last): 88 ... 89 https-test-client.TestExpectationFailed: Unexpected body: 'xyz\\n' != 'test\\n' 90 >>> r2 = TestRequest(path='/test.txt', method='GET', headers={}, expect={'status': 200, 'body': {'contains': ['tes', 'est']}}) 91 >>> r2._check_body('test\\n') 92 >>> r2._check_body('est\\n') 93 Traceback (most recent call last): 94 ... 95 https-test-client.TestExpectationFailed: Unexpected body: 'est\\n' does not contain 'tes' 96 >>> r3 = TestRequest(path='/test.txt', method='GET', headers={}, expect={'status': 200, 'body': {'contains': 'test'}}) 97 >>> r3._check_body('test\\n') 98 """ 99 if 'exactly' in self.expect['body'] \ 100 and body != self.expect['body']['exactly']: 101 raise TestExpectationFailed( 102 f'Unexpected body: {body!r} != ' 103 f'{self.expect["body"]["exactly"]!r}') 104 if 'contains' in self.expect['body']: 105 if type(self.expect['body']['contains']) is str: 106 self.expect['body']['contains'] = [ 107 self.expect['body']['contains']] 108 for s in self.expect['body']['contains']: 109 if not s in body: 110 raise TestExpectationFailed( 111 f'Unexpected body: {body!r} does not contain ' 112 f'{s!r}') 81 113 82 114 def check_response(self, response, body): … … 85 117 f'Unexpected status: {response.status} != ' 86 118 f'{self.expect["status"]}') 87 if 'body' in self.expect and self.expect['body'] != body: 88 raise TestExpectationFailed( 89 f'Unexpected body: {body!r} != {self.expect["body"]!r}') 119 if 'body' in self.expect: 120 self._check_body(body) 90 121 91 122 @classmethod -
test/sample_test.yml
ra4e136a r096859f 14 14 expect: 15 15 status: 200 16 body: | 17 test 16 body: 17 exactly: | 18 test 19 - !request 20 path: /test.txt 21 expect: 22 status: 200 23 body: 24 contains: 25 - 'tes' 26 - 'est'
Note: See TracChangeset
for help on using the changeset viewer.