def test_proxy_reponse_post(mock_search): mock_search.return_value = index.proxy_reponse('{}') index.proxy_request({ 'body': '<SEARCH_XML>', 'httpMethod': 'POST', 'path': '/simple/', }) mock_search.assert_called_once_with('<SEARCH_XML>')
def test_proxy_request_reject(http_method, path, status_code): ret = index.proxy_request({'httpMethod': http_method, 'path': path}) exp = index.reject(status_code, message='Forbidden') if http_method == 'HEAD': exp['body'] = '' exp['headers']['Content-Length'] = 0 assert ret == exp
def test_handler_get_root(): event = {'httpMethod': 'GET', 'path': '/'} ret = index.proxy_request(event) exp = { 'statusCode': 301, 'headers': { 'Location': '/simple/', }, } assert ret == exp
def get_response(self, httpMethod): # Log request headers self.log_headers() logging.info(f'PATH -- {self.path}') # Construct event event = { 'httpMethod': httpMethod, 'path': self.path, } # Get response response = index.proxy_request(event) status = response.get('statusCode') headers = response.get('headers') self.send_response(status) for key, val in headers.items(): self.send_header(key, val) self.end_headers()
def test_proxy_request_reject(event, status_code, msg): ret = index.proxy_request(event) exp = index.reject(status_code, message=msg) assert ret == exp
def test_proxy_request_get_package(event): with mock.patch('index.get_package_index') as mock_pkg: mock_pkg.return_value = index.proxy_reponse(PACKAGE_INDEX) index.proxy_request(event) mock_pkg.assert_called_once_with('fizz')
def test_proxy_reponse_post(event): with mock.patch('index.search') as mock_search: mock_search.return_value = index.proxy_reponse('{}') index.proxy_request(event) mock_search.assert_called_once_with('<SEARCH_XML>')
def test_proxy_request_get(event): with mock.patch('index.get_index') as mock_idx: mock_idx.return_value = index.proxy_reponse(SIMPLE_INDEX) index.proxy_request(event) mock_idx.assert_called_once_with()
def test_handler_get_root(event, exp): ret = index.proxy_request(event) assert ret == exp
def test_proxies_request(self): response = index.proxy_request(self.event, self.context) self.assertEqual(self.event["payload"], response["form"])
def test_proxy_request_get_package(mock_pkg): mock_pkg.return_value = index.proxy_reponse(PACKAGE_INDEX) index.proxy_request({'httpMethod': 'GET', 'path': '/simple/fizz/'}) mock_pkg.assert_called_once_with('fizz')
def test_proxy_request_get(mock_idx): mock_idx.return_value = index.proxy_reponse(SIMPLE_INDEX) index.proxy_request({'httpMethod': 'GET', 'path': '/simple/'}) mock_idx.assert_called_once_with()
def test_proxy_request_reject(http_method, path, status_code): ret = index.proxy_request({'httpMethod': http_method, 'path': path}) exp = index.reject(status_code) assert ret == exp