Exemplo n.º 1
0
 def test_error_value_error(self, mock_trace):
     mock_trace.return_value = "test trace"
     fault_wrapper = fault.FaultWrapper(None)
     exception = exceptions.PackageClassLoadError("test")
     exception.message = "Unable to load class 'test' from package"
     result = fault_wrapper._error(exception)
     self.assertEqual(result['code'], 400)
     self.assertEqual(result['error']['message'],
                      "Unable to load class 'test' from package")
Exemplo n.º 2
0
 def test_error_500(self, mock_trace):
     mock_trace.return_value = "test trace"
     fault_wrapper = fault.FaultWrapper(None)
     result = fault_wrapper._error(exc.HTTPInternalServerError())
     self.assertEqual(result['code'], 500)
     self.assertEqual(
         result['explanation'],
         'The server has either erred or is incapable'
         ' of performing the requested operation.')
Exemplo n.º 3
0
 def test_process_request(self):
     fault_wrapper = fault.FaultWrapper(None)
     environ = {
         'SERVER_NAME': 'server.test',
         'SERVER_PORT': '8082',
         'SERVER_PROTOCOL': 'http',
         'SCRIPT_NAME': '/',
         'PATH_INFO': '/asdf/asdf/asdf/asdf',
         'wsgi.url_scheme': 'http',
         'QUERY_STRING': '',
         'CONTENT_TYPE': 'application/json',
         'REQUEST_METHOD': 'HEAD'
     }
     req = wsgi.Request(environ)
     req.get_response = mock.MagicMock(
         side_effect=exc.HTTPInternalServerError())
     self.assertRaises(exc.HTTPInternalServerError,
                       fault_wrapper.process_request, req)
Exemplo n.º 4
0
 def test_fault_call(self, mock_trace):
     mock_trace.return_value = "test trace"
     fault_wrapper = fault.FaultWrapper(None)
     exception = exceptions.PackageClassLoadError("test")
     exception.message = "Unable to load class 'test' from package"
     test_fault = fault.Fault(fault_wrapper._error(exception))
     environ = {
         'SERVER_NAME': 'server.test',
         'SERVER_PORT': '8082',
         'SERVER_PROTOCOL': 'http',
         'SCRIPT_NAME': '/',
         'PATH_INFO': '/',
         'wsgi.url_scheme': 'http',
         'QUERY_STRING': '',
         'CONTENT_TYPE': 'application/json',
         'REQUEST_METHOD': 'HEAD'
     }
     req = wsgi.Request(environ)
     response = jsonutils.loads(test_fault(req).body)
     self.assertEqual(response['code'], 400)