Exemple #1
0
    def test_flask_dispatch_wrapper_fail(self):
        """
        Tests the response when their is a failure in
        dispatching a request that is not a RestException
        """
        adapter_class = self.get_mock_adapter_class()

        def fake(*args, **kwargs):
            raise Exception

        d = FlaskDispatcher(self.app)
        d.register_adapters(adapter_class)
        view_func = flask_dispatch_wrapper(d, fake)
        self.assertEqual(view_func.__name__, fake.__name__)

        with self.app.test_request_context('/myresource'):
            self.assertRaises(Exception, view_func)
Exemple #2
0
    def test_flask_dispatch_wrapper(self):
        """
        Tests the wrapper to ensure that it properly calls the
        apimethod
        """
        adapter_class = self.get_mock_adapter_class()

        def fake(*args, **kwargs):
            return mock.Mock()

        d = FlaskDispatcher(self.app)
        d.register_adapters(adapter_class)
        view_func = flask_dispatch_wrapper(d, fake)
        self.assertEqual(view_func.__name__, fake.__name__)

        with self.app.test_request_context('/myresource'):
            response = view_func()
            self.assertEqual(response.content_type, 'fake')
            self.assertEqual(response.status_code, 600)
            self.assertEqual(response.data.decode('utf8'), 'some body')
Exemple #3
0
    def test_flask_dispatch_wrapper_fail_restexception(self):
        """
        Tests the response when their is a failure in
        dispatching a request. In particular when a RestException
        is raised.
        """
        adapter_class = self.get_mock_adapter_class()

        def fake(*args, **kwargs):
            raise RestException

        d = FlaskDispatcher(self.app)
        d.register_adapters(adapter_class)
        view_func = flask_dispatch_wrapper(d, fake)
        self.assertEqual(view_func.__name__, fake.__name__)

        with self.app.test_request_context('/myresource'):
            response = view_func()
            self.assertEqual(response.status_code, 500)
            self.assertEqual(response.data.decode('utf8'), 'error')
            self.assertEqual(response.content_type, 'fake')