示例#1
0
    def test_no_overwriting_of_managed_objects(self):
        env = Environment()
        managed = object()
        env.add_managed_object('i_am_managed', managed)

        self.assertEqual(managed, env.i_am_managed)
        with self.assertRaises(AssertionError):
            env.add_managed_object('i_am_managed', object())
示例#2
0
 def test_simple_app_creation(self):
     env = Environment()
     app = env.get_application()
     self.assertIsInstance(app, Application)
     if tornado.version < '4.5':
         self.assertEqual(len(app.handlers), 2)
     else:
         self.assertEqual(len(app.default_router.rules), 2)
    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()
    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()
示例#5
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()
示例#6
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()
示例#7
0
    def test_finalizing(self):
        env = Environment()
        managed = object()
        env.add_managed_object('i_am_managed', managed)
        env._finalize()

        with self.assertRaises(AssertionError):
            env.add_managed_object('another_managed', object())
示例#8
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()
示例#9
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()
示例#10
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)
示例#11
0
    def test_finalizing(self):
        env = Environment()
        managed = object()
        env.add_managed_object('i_am_managed', managed)
        env._finalize()

        with self.assertRaises(AssertionError):
            env.add_managed_object('another_managed', object())
示例#12
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)
示例#13
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)
示例#14
0
    def test_no_overwriting_of_managed_objects(self):
        env = Environment()
        managed = object()
        env.add_managed_object('i_am_managed', managed)

        self.assertEqual(managed, env.i_am_managed)
        with self.assertRaises(AssertionError):
            env.add_managed_object('i_am_managed', object())
    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()
示例#16
0
 def get_app(self):
     env = Environment()
     env.add_handler("/test", MyQueryparamHandlerWithCustomKwargsName)
     env.tornado_settings["debug"] = True
     return env.get_application()
示例#17
0
 def get_app(self):
     env = Environment()
     env.add_handler('/teststats', MyHandler)
     env.add_handler('/_system/stats(.*)', ScalesSupercellHandler)
     return env.get_application()
示例#18
0
    def test_managed_object_access(self):
        env = Environment()

        managed = object()
        env.add_managed_object('i_am_managed', managed)
        self.assertEqual(managed, env.i_am_managed)
示例#19
0
 def environment(self):
     """The default environment instance."""
     if not hasattr(self, '_environment'):
         self._environment = Environment()
     return self._environment
示例#20
0
 def test_simple_app_creation(self):
     env = Environment()
     app = env.get_application()
     self.assertIsInstance(app, Application)
     self.assertEqual(len(app.handlers), 2)
示例#21
0
 def get_app(self):
     env = Environment()
     env.add_handler('/_system/check', SystemHealthCheck)
     return env.get_application()
示例#22
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()
示例#23
0
 def test_config_file_paths(self):
     env = Environment()
     self.assertEqual(len(env.config_file_paths), 0)
示例#24
0
 def test_simple_app_creation(self):
     env = Environment()
     app = env.get_application()
     self.assertIsInstance(app, Application)
     self.assertEqual(len(app.handlers), 2)
示例#25
0
 def get_app(self):
     env = Environment()
     env.add_handler('/test', MyQueryparamHandler)
     env.tornado_settings['debug'] = True
     return env.get_application()
示例#26
0
 def get_app(self):
     env = Environment()
     env.add_handler('/testencoding/(.*)', EncodingTestingHandler)
     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()
示例#28
0
    def test_managed_object_access(self):
        env = Environment()

        managed = object()
        env.add_managed_object('i_am_managed', managed)
        self.assertEqual(managed, env.i_am_managed)
示例#29
0
 def get_app(self):
     env = Environment()
     env.add_handler('/_system/check', SystemHealthCheck)
     return env.get_application()
示例#30
0
 def get_app(self):
     env = Environment()
     env.add_health_check('test', SimpleHealthCheckExample)
     env.add_health_check('error', SimpleErrorCheckExample)
     return env.get_application()
示例#31
0
 def get_app(self):
     env = Environment()
     env.add_handler('/test', MyQueryparamHandler)
     env.tornado_settings['debug'] = True
     return env.get_application()
示例#32
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()
示例#34
0
 def get_app(self):
     env = Environment()
     env.add_health_check('test', SimpleHealthCheckExample)
     env.add_health_check('error', SimpleErrorCheckExample)
     return env.get_application()
示例#35
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()