Example #1
0
    def test_detect_view_name(self):
        """ test detect_view_name """
        target = self._make_one()
        environ = setup_environ()
        result = target.detect_view_name(environ)

        compare(result, None)
    def test_call(self):
        """ test basic using """

        class DummyAction(object):
            """ dummy action class"""
            def __init__(self):
                self.message = b"Hello"

            def get_message(self):
                """ get message to return body"""
                return self.message

            def action(self, _, start_response):
                """ dummy action """
                start_response("200 OK",
                               [("Content-type", "text/plain")])
                return [self.get_message()]

        target = self._call_fut(DummyAction, "action")
        environ = setup_environ(REQUEST_METHOD='POST')
        start_response = mock.Mock()
        result = target(environ, start_response)
        compare(result, [b"Hello"])
        start_response.assert_called_with(
            '200 OK', [('Content-type', 'text/plain')])
 def test_it(self):
     """ test basic using"""
     app = self._make_one(get=dummy_get_app)
     environ = setup_environ()
     start_response = mock.Mock()
     result = app(environ, start_response)
     compare(result, ["get"])
 def test_register_app(self):
     """ test registering app"""
     app = self._make_one()
     app.register_app("get", dummy_get_app)
     environ = setup_environ()
     start_response = mock.Mock()
     result = app(environ, start_response)
     compare(result, ["get"])
Example #5
0
    def test_init(self):
        """ test create object """
        environ = setup_environ()
        urlmapper = object()
        target = self._make_one(environ, urlmapper)

        compare(target.environ, environ)
        compare(target.urlmapper, urlmapper)
        compare(target.application_uri, 'http://127.0.0.1/')
 def test_not_allowed(self):
     """ test not found views"""
     app = self._make_one(get=dummy_get_app)
     environ = setup_environ(REQUEST_METHOD='POST')
     start_response = mock.Mock()
     result = app(environ, start_response)
     compare(result, [b"Method Not Allowed"])
     start_response.assert_called_with(
         '405 Method Not Allowed', [('Content-type', 'text/plain')])
Example #7
0
    def test_on_view_not_found(self):
        """ test on_view_not_found """
        target = self._make_one()
        environ = setup_environ()
        start_response = mock.Mock()
        result = target(environ, start_response)

        compare(result, [b'Not found'])
        start_response.assert_called_with(
            '404 Not Found', [('Content-type', 'text/plain')])
Example #8
0
    def test_generate(self):
        """ test generating url """
        environ = setup_environ()
        urlmapper = mock.Mock()
        urlmapper.generate.return_value = 'testing-route-url'
        target = self._make_one(environ, urlmapper)

        result = target.generate('testing-route', v1="a")

        compare(result, 'http://127.0.0.1/testing-route-url')
 def test_register_app_decorator(self):
     """ test registering app"""
     app = self._make_one()
     dec = app.register_app("get")
     controller = dummy_get_app
     ret = dec(controller)
     compare(ret, controller)
     environ = setup_environ()
     start_response = mock.Mock()
     result = app(environ, start_response)
     compare(result, ["get"])
    def test_it(self):
        """ test for basic usage"""
        app = self._make_one()

        def test_app(*_):
            """ dummy app"""
            return [b'got action']

        app.register_app('test_app', test_app)
        routing_args = [(), {'action': 'test_app'}]
        environ = setup_environ()
        environ.update({'wsgiorg.routing_args': routing_args})
        start_response = mock.Mock()
        result = app(environ, start_response)
        compare(result, [b"got action"])
    def test_not_found(self):
        """ test called not registered action """

        app = self._make_one()
        app.register_app('test_app',
                         None)
        routing_args = [(), {'action': 'no_app'}]
        env = {'wsgiorg.routing_args': routing_args}
        environ = setup_environ()
        environ.update(env)
        start_response = mock.Mock()
        result = app(environ, start_response)
        start_response.assert_called_with(
            '404 Not Found', [('Content-type', 'text/plain')])

        compare(result,
                [b"Not Found ",
                 b"http://127.0.0.1/"])
    def test_register_action_handler(self):
        """ test register """
        app = self._make_one()

        class DummyHandler(object):
            """ dummy handler """

            @staticmethod
            def get_body():
                """ get body to return action """
                return [b"test action"]

            def test_action(self, *_):
                """ dummy action """
                return self.get_body()

        app.register_actionhandler(DummyHandler)
        routing_args = [(), {'action': 'test_action'}]
        environ = setup_environ()
        environ.update({'wsgiorg.routing_args': routing_args})
        start_response = mock.Mock()
        result = app(environ, start_response)
        compare(result, [b"test action"])