Beispiel #1
0
    def setUp(self):
        self.app = Kobin(config={'DEBUG': True})
        self.before_counter = 0

        @self.app.route('/')
        def dummy_func():
            return Response('hello')
Beispiel #2
0
 def test_constructor_headerlist_has_location(self):
     test_env = {'HTTP_HOST': 'localhost', 'SERVER_PROTOCOL': 'HTTP/1.1'}
     app = Kobin()
     app(test_env, lambda x, y: None)
     response = RedirectResponse('/hello')
     expected_content_type = ('Location', 'http://localhost/hello')
     self.assertIn(expected_content_type, response.headerlist)
Beispiel #3
0
    def setUp(self):
        self.app = Kobin()
        self.dummy_start_response = lambda x, y: None
        self.before_counter = 0

        @self.app.route('/')
        def dummy_func():
            return Response('hello')

        @self.app.before_request
        def before():
            self.before_counter += 1

        @self.app.before_request
        def before2():
            self.before_counter += 1

        @self.app.after_request
        def after(response):
            response.headers.add_header('Foo1', 'Bar1')
            return response

        @self.app.after_request
        def after2(response):
            response.headers.add_header('Foo2', 'Bar2')
            return response
Beispiel #4
0
    def setUp(self):
        self.app = Kobin()
        self.dummy_start_response = lambda x, y: None

        @self.app.route('/')
        def dummy_func():
            return 'hello'

        @self.app.route('/test/{typed_id}')
        def typed_url_var(typed_id: int):
            return typed_id
Beispiel #5
0
    def test_lazy_reverse_router(self, app_mock):
        app = Kobin()

        @app.route('/', 'GET', 'top')
        def top():
            return Response('Hello')

        app_mock.return_value = app
        actual = template_router_reverse('top')

        expected = '/'
        self.assertEqual(actual, expected)
Beispiel #6
0
    def setUp(self):
        self.app = Kobin()
        self.dummy_start_response = lambda x, y: None
        self.before_counter = 0

        @self.app.route('/')
        def dummy_func():
            return Response('hello')

        @self.app.after_request
        def after_do_not_return_response(response):
            pass
Beispiel #7
0
    def setUp(self):
        self.app = Kobin()
        self.dummy_start_response = lambda x, y: None

        @self.app.route('/')
        def dummy_func():
            return Response('hello')

        @self.app.route('/test/{typed_id}')
        def typed_url_var(typed_id: int):
            body = "type: {}, value: {}".format(type(typed_id), typed_id)
            return Response(body)

        @self.app.route('/test/raise500')
        def raise500(typed_id: int):
            1 / 0
            return Response("Don't reach here")
Beispiel #8
0
 def test_constructor_status_when_http11(self):
     test_env = {'HTTP_HOST': 'localhost', 'SERVER_PROTOCOL': 'HTTP/1.1'}
     app = Kobin()
     app(test_env, lambda x, y: None)
     response = RedirectResponse('/')
     self.assertEqual(response.status_code, 303)
Beispiel #9
0
from kobin import Kobin

app = Kobin()


@app.route('^/(?P<name>\w*)$')
def hello(name: str) -> str:
    return "Hello {}!!".format(name)


if __name__ == '__main__':
    app.run()
Beispiel #10
0
import os
from kobin import Kobin, load_config_from_pyfile
from . import views

config = load_config_from_pyfile(os.environ.get('KOBIN_SETTINGS_FILE', 'app/config.py'))
app = Kobin(config=config)
views.setup_routing(app)
Beispiel #11
0
 def test_lazy_reverse_router_not_found(self, app_mock):
     app = Kobin()
     app_mock.return_value = app
     actual = template_router_reverse('top')
     expected = ''
     self.assertEqual(actual, expected)