def get_app(self):
        @provides(s.MediaType.ApplicationJson, default=True)
        class MyHandler(RequestHandler):
            @s. async
            def get(self, *args, **kwargs):
                model = self.load_model_from_arguments(SimpleModel,
                                                       name="default")
                raise s.Return(model)

        env = Environment()
        env.add_handler('/test', MyHandler)
        return env.get_application()
Exemplo n.º 2
0
    def get_app(self):

        @provides(s.MediaType.ApplicationJson, default=True)
        class MyHandler(RequestHandler):

            @s.coroutine
            def get(self, *args, **kwargs):
                model = self.load_model_from_arguments(
                    SimpleModel, name="default")
                raise s.Return(model)

        env = Environment()
        env.add_handler('/test', MyHandler)
        return env.get_application()
Exemplo n.º 3
0
    def get_app(self):

        @provides(s.MediaType.TextHtml, default=True)
        class SimpleHtmlHandler(s.RequestHandler):

            @s.coroutine
            def get(self, *args, **kwargs):
                r = SimpleMessage({'doc_id': 'test123',
                                   'message': 'args=%s; kwargs=%s' % (args,
                                                                      kwargs)})
                raise s.Return(r)

        env = Environment()
        env.add_handler('/test_html/(.*)', SimpleHtmlHandler)
        d = op.dirname(__file__)
        env.tornado_settings['template_path'] = op.join(d,
                                                        'html_test_template')
        return env.get_application()
Exemplo n.º 4
0
    def test_add_handler(self):
        env = Environment()
        self.assertEqual(len(env._handlers), 0)

        class MyHandler(RequestHandler):
            def get(self):
                self.write({'ok': True})

        env.add_handler('/test', MyHandler, {})

        self.assertEqual(len(env._handlers), 1)

        app = env.get_application()

        request = httputil.HTTPServerRequest(uri='/test')
        handler_delegate = app.default_router.find_handler(request)
        self.assertIsNotNone(handler_delegate)
        self.assertEqual(handler_delegate.handler_class, MyHandler)
    def get_app(self):
        @provides(s.MediaType.TextHtml, default=True)
        class SimpleHtmlHandler(s.RequestHandler):
            @s. async
            def get(self, *args, **kwargs):
                r = SimpleMessage({
                    'doc_id':
                    'test123',
                    'message':
                    'args=%s; kwargs=%s' % (args, kwargs)
                })
                raise s.Return(r)

        env = Environment()
        env.add_handler('/test_html/(.*)', SimpleHtmlHandler)
        d = op.dirname(__file__)
        env.tornado_settings['template_path'] = op.join(
            d, 'html_test_template')
        return env.get_application()
Exemplo n.º 6
0
    def test_add_handler(self):
        env = Environment()
        self.assertEqual(len(env._handlers), 0)

        class MyHandler(RequestHandler):
            def get(self):
                self.write({'ok': True})

        env.add_handler('/test', MyHandler, {})

        self.assertEqual(len(env._handlers), 1)

        app = env.get_application()
        self.assertEqual(len(app.handlers), 3)
        (host_pattern, [spec]) = [h for h in app.handlers
                                  if not h[1][0].regex.pattern.startswith(
                                      '/_system')][0]
        self.assertEqual(host_pattern.pattern, '.*$')
        self.assertEqual(spec.regex.pattern, '/test$')
        self.assertEqual(spec.handler_class, MyHandler)
Exemplo n.º 7
0
    def test_add_handler(self):
        env = Environment()
        self.assertEqual(len(env._handlers), 0)

        class MyHandler(RequestHandler):
            def get(self):
                self.write({'ok': True})

        env.add_handler('/test', MyHandler, {})

        self.assertEqual(len(env._handlers), 1)

        app = env.get_application()
        self.assertEqual(len(app.handlers), 3)
        (host_pattern, [spec]) = [
            h for h in app.handlers
            if not h[1][0].regex.pattern.startswith('/_system')
        ][0]
        self.assertEqual(host_pattern.pattern, '.*$')
        self.assertEqual(spec.regex.pattern, '/test$')
        self.assertEqual(spec.handler_class, MyHandler)
Exemplo n.º 8
0
    def get_app(self):

        @provides(s.MediaType.ApplicationJson)
        class MyHandlerWithoutPartial(RequestHandler):

            @s.coroutine
            def get(self, *args, **kwargs):
                raise s.Return(StricterMessage({"doc_id": 'test123'}))

        @provides(s.MediaType.ApplicationJson, partial=True)
        class MyHandlerWithPartial(RequestHandler):

            @s.coroutine
            def get(self, *args, **kwargs):
                raise s.Return(StricterMessage({"doc_id": 'test123'}))

        @provides(s.MediaType.ApplicationJson, partial=True)
        class MyHandlerWithPartialComplex(RequestHandler):

            @s.coroutine
            def get(self, *args, **kwargs):
                raise s.Return(StricterMessageCollection(
                    {"messages": [{"doc_id": 'test123'}]}))

        env = Environment()
        env.add_handler('/test_no_partial', MyHandlerWithoutPartial)
        env.add_handler('/test_partial', MyHandlerWithPartial)
        env.add_handler('/test_partial_complex', MyHandlerWithPartialComplex)
        return env.get_application()
    def get_app(self):
        @provides(s.MediaType.ApplicationJson)
        class MyHandlerWithoutPartial(RequestHandler):
            @s. async
            def get(self, *args, **kwargs):
                raise s.Return(StricterMessage({"doc_id": 'test123'}))

        @provides(s.MediaType.ApplicationJson, partial=True)
        class MyHandlerWithPartial(RequestHandler):
            @s. async
            def get(self, *args, **kwargs):
                raise s.Return(StricterMessage({"doc_id": 'test123'}))

        @provides(s.MediaType.ApplicationJson, partial=True)
        class MyHandlerWithPartialComplex(RequestHandler):
            @s. async
            def get(self, *args, **kwargs):
                raise s.Return(
                    StricterMessageCollection(
                        {"messages": [{
                            "doc_id": 'test123'
                        }]}))

        env = Environment()
        env.add_handler('/test_no_partial', MyHandlerWithoutPartial)
        env.add_handler('/test_partial', MyHandlerWithPartial)
        env.add_handler('/test_partial_complex', MyHandlerWithPartialComplex)
        return env.get_application()
Exemplo n.º 10
0
 def get_app(self):
     env = Environment()
     env.add_handler(r'/', MyHandler,
                     cache=CacheConfig(timedelta(minutes=10)))
     env.add_handler(r'/cache', MyExtremeCachingHandler,
                     cache=CacheConfig(timedelta(minutes=10),
                                       s_max_age=timedelta(minutes=10),
                                       public=True, must_revalidate=True,
                                       proxy_revalidate=True),
                     expires=timedelta(minutes=15))
     env.add_handler(r'/private', MyPrivateCaching,
                     cache=CacheConfig(timedelta(seconds=10),
                                       s_max_age=timedelta(seconds=0),
                                       private=True, no_store=True))
     env.add_handler(r'/nested_async', CachingWithYielding,
                     cache=CacheConfig(timedelta(seconds=10)))
     return env.get_application()
Exemplo n.º 11
0
 def get_app(self):
     env = Environment()
     env.add_handler(r'/',
                     MyHandler,
                     cache=CacheConfig(timedelta(minutes=10)))
     env.add_handler(r'/cache',
                     MyExtremeCachingHandler,
                     cache=CacheConfig(timedelta(minutes=10),
                                       s_max_age=timedelta(minutes=10),
                                       public=True,
                                       must_revalidate=True,
                                       proxy_revalidate=True),
                     expires=timedelta(minutes=15))
     env.add_handler(r'/private',
                     MyPrivateCaching,
                     cache=CacheConfig(timedelta(seconds=10),
                                       s_max_age=timedelta(seconds=0),
                                       private=True,
                                       no_store=True))
     env.add_handler(r'/nested_async',
                     CachingWithYielding,
                     cache=CacheConfig(timedelta(seconds=10)))
     return env.get_application()
Exemplo n.º 12
0
 def get_app(self):
     env = Environment()
     env.add_handler("/teststats", MyHandler)
     env.add_handler("/_system/stats(.*)", ScalesSupercellHandler)
     return env.get_application()
Exemplo n.º 13
0
 def get_app(self):
     env = Environment()
     env.add_handler('/_system/check', SystemHealthCheck)
     return env.get_application()
Exemplo n.º 14
0
 def get_app(self):
     env = Environment()
     env.add_handler('/test', MyHandler)
     env.add_handler('/test_default', MyHandlerWithDefault)
     env.add_handler('/test_echo', MyEchoHandler)
     return env.get_application()
Exemplo n.º 15
0
 def get_app(self):
     env = Environment()
     env.add_handler("/test", MyQueryparamHandlerWithCustomKwargsName)
     env.tornado_settings["debug"] = True
     return env.get_application()
Exemplo n.º 16
0
 def get_app(self):
     env = Environment()
     env.add_handler('/test', MyQueryparamHandler)
     env.tornado_settings['debug'] = True
     return env.get_application()
Exemplo n.º 17
0
 def get_app(self):
     env = Environment()
     env.add_handler('/teststats', MyHandler)
     env.add_handler('/_system/stats(.*)', ScalesSupercellHandler)
     return env.get_application()
 def get_app(self):
     env = Environment()
     env.add_handler('/testencoding/(.*)', EncodingTestingHandler)
     return env.get_application()
Exemplo n.º 19
0
 def get_app(self):
     env = Environment()
     env.add_handler('/testencoding/(.*)', EncodingTestingHandler)
     return env.get_application()
Exemplo n.º 20
0
 def get_app(self):
     env = Environment()
     env.add_handler('/test', MyQueryparamHandler)
     env.tornado_settings['debug'] = True
     return env.get_application()
 def get_app(self):
     env = Environment()
     env.add_handler('/test', MyHandler)
     env.add_handler('/test_default', MyHandlerWithDefault)
     env.add_handler('/test_echo', MyEchoHandler)
     return env.get_application()
Exemplo n.º 22
0
 def get_app(self):
     env = Environment()
     env.add_handler('/_system/check', SystemHealthCheck)
     return env.get_application()