def setUp(self): ef.clear() self.app = Client() self.account = ef.account(type=AccountType.ADMIN.value) token = AuthToken.encode(self.account) self.headers = {'HTTP_AUTHORIZATION': f'Bearer {token}'}
def setUp(self): self.app = Client() self.auth_headers = { 'HTTP_X_CS_ACCOUNT_TYPE': 'ADMIN', 'HTTP_X_CS_USER_ID': 190, } self.lily_dir = self.tmpdir.mkdir('.lily') self.commands_dir = self.lily_dir.mkdir('commands') MockConfig._lily_path = str(self.lily_dir) self.mocker.patch( 'entrypoint.commands.Config', MockConfig)
def test_http_response(self): examples_file = self.prepare_example_file() response = Client().get('/http/it/') assert response.status_code == 200 assert json.loads(examples_file.read()) == { 'HTTP_IT': { '200': { 'method': 'get', 'description': None, 'request': { 'path': '/http/it/', }, 'response': { 'status': 200, 'content_type': 'text/html; charset=utf-8', 'content': 'http it!', }, }, }, }
def test_multiple_same_responses_single_endpoint(self): examples_file = self.prepare_example_file() Client().get('/test/it/?type=a') Client().get('/test/it/?type=b') Client().get('/test/it/?type=c') Client().get('/test/it/?type=c') Client().get('/test/it/?type=b') Client().get('/test/it/?type=c') assert json.loads(examples_file.read()) == { 'GET_IT': { '200 (LISTED)': { 'method': 'get', 'description': 'LISTED', 'request': { 'path': '/test/it/?type=b', }, 'response': { 'status': 200, 'content_type': 'application/json', 'content': { '@type': 'test', '@event': 'LISTED', 'hello': 'get.b', }, } }, '200 (LISTED_AGAIN)': { 'method': 'get', 'description': 'LISTED_AGAIN', 'request': { 'path': '/test/it/?type=c', }, 'response': { 'status': 200, 'content_type': 'application/json', 'content': { '@type': 'test', '@event': 'LISTED_AGAIN', 'hello': 'get.c', }, }, }, }, }
def test_multiple_responses_for_multiple_endpoints(self): examples_file = self.prepare_example_file() Client().get('/test/it/?type=a') Client().get('/test/it/?type=b') Client().get('/test/it/?type=a') Client().delete('/test/it/') Client().get('/test/it/?type=d') Client().put('/test/it/') assert json.loads(examples_file.read()) == { 'GET_IT': { '200 (LISTED)': { 'method': 'get', 'description': 'LISTED', 'request': { 'path': '/test/it/?type=a' }, 'response': { 'status': 200, 'content_type': 'application/json', 'content': { '@type': 'test', '@event': 'LISTED', 'hello': 'get.a', }, } }, '404 (ERROR_LISTED)': { 'method': 'get', 'description': 'ERROR_LISTED', 'request': { 'path': '/test/it/?type=d' }, 'response': { 'status': 404, 'content_type': 'application/json', 'content': { '@type': 'error', '@event': 'ERROR_LISTED', 'hello': 'get.d', }, } }, }, 'DELETE_IT': { '200 (DELETED)': { 'method': 'delete', 'description': 'DELETED', 'request': { 'path': '/test/it/' }, 'response': { 'status': 200, 'content_type': 'application/json', 'content': { '@type': 'test', '@event': 'DELETED', 'hello': 'delete', }, }, } }, 'PUT_IT': { '200 (UPDATED)': { 'method': 'put', 'description': 'UPDATED', 'request': { 'path': '/test/it/' }, 'response': { 'status': 200, 'content_type': 'application/json', 'content': { '@type': 'test', '@event': 'UPDATED', 'hello': 'put', }, }, } }, }
def setUp(self): ef.clear() self.app = Client()