def test_stuf(self, mock_flask, mock_handle_stuf): mock_flask.request.method = 'GET' mock_flask.request.url = "any url" mock_flask.request.data = b"any data" mock_flask.request.headers = { 'Soapaction': 'zeepactie', } mock_flask.request.remote_addr = '1.2.3.4' response = _stuf() self.assertEqual(response.data, b"get")
def test_stuf_exception(self, mock_flask, mock_handle_stuf): mock_handle_stuf.side_effect = BadRequest("Exception message") mock_flask.request.method = 'GET' mock_flask.request.url = "any url" mock_flask.request.data = b"any data" mock_flask.request.headers = { 'Soapaction': 'zeepactie', } mock_flask.request.remote_addr = '1.2.3.4' with self.assertRaises(BadRequest): response = _stuf()
def test_stuf_exception(self, mock_uuid, mock_flask, mock_handle_stuf, mock_audit_logger): mock_handle_stuf.side_effect = BadRequest("Exception message") mock_flask.request.method = 'GET' mock_flask.request.url = "any url" mock_flask.request.data = b"any data" mock_flask.request.headers = { 'Soapaction': 'zeepactie', } mock_flask.request.remote_addr = '1.2.3.4' with self.assertRaises(BadRequest): response = _stuf() # Make sure audit log is called audit_logger_instance = mock_audit_logger.get_instance.return_value audit_logger_instance.log_request.assert_called_with( '1.2.3.4', 'ROUTE_SCHEME://ROUTE_NETLOC/any url', { 'soapaction': 'zeepactie', 'original_url': 'any url', 'method': 'GET', }, 'the uuid', ) audit_logger_instance.log_response.assert_called_with( '1.2.3.4', 'ROUTE_SCHEME://ROUTE_NETLOC/any url', { 'soapaction': 'zeepactie', 'exception': '400 Bad Request: Exception message', 'original_url': 'any url', 'method': 'GET', }, 'the uuid', )
def test_stuf(self, mock_uuid, mock_flask, mock_handle_stuf, mock_audit_logger): mock_flask.request.method = 'GET' mock_flask.request.url = "any url" mock_flask.request.data = b"any data" mock_flask.request.headers = { 'Soapaction': 'zeepactie', } mock_flask.request.remote_addr = '1.2.3.4' response = _stuf() self.assertEqual(response.data, b"get") # Make sure audit log is called audit_logger_instance = mock_audit_logger.get_instance.return_value audit_logger_instance.log_request.assert_called_with( '1.2.3.4', 'ROUTE_SCHEME://ROUTE_NETLOC/any url', { 'soapaction': 'zeepactie', 'original_url': 'any url', 'method': 'GET', }, 'the uuid', ) audit_logger_instance.log_response.assert_called_with( '1.2.3.4', 'ROUTE_SCHEME://ROUTE_NETLOC/any url', { 'soapaction': 'zeepactie', 'remote_response_code': 123, 'original_url': 'any url', 'method': 'GET', }, 'the uuid', )