Example #1
0
    def setup_servlet(self):
        application = turtle.Turtle()
        application.settings = {
            'static_path':
            os.path.join(os.path.dirname(__file__), "../static"),
            'template_path':
            os.path.join(os.path.dirname(__file__), "../templates"),
            'autoescape':
            None,
        }

        # Properly load ui_modules and ui_methods
        application.ui_modules = {}
        application.ui_methods = {}
        application._load_ui_modules = types.MethodType(
            tornado.web.Application._load_ui_modules.im_func, application)
        application._load_ui_methods = types.MethodType(
            tornado.web.Application._load_ui_methods.im_func, application)
        application._load_ui_modules(ui_modules)
        application._load_ui_methods(ui_methods)

        if self.authenticated:
            application.settings['cookie_secret'] = 'cookie_secret'
        request = turtle.Turtle()
        self.servlet = RequestHandler(application, request)
 def test_get_api_page(self):
     MockedSettings['api_app'] = {'port': 8043, 'servername': 'push.test.com'}
     with mock.patch.dict(Settings, MockedSettings):
         T.assert_equal(
             RequestHandler.get_api_page("pushes"),
             "http://push.test.com:8043/api/pushes"
         )
 def test_get_api_page(self):
     MockedSettings['api_app'] = {'port': 8043, 'servername': 'push.test.com'}
     with mock.patch.dict(Settings, MockedSettings):
         T.assert_equal(
             RequestHandler.get_api_page("pushes"),
             "http://push.test.com:8043/api/pushes"
         )
Example #4
0
class TemplateTestCase(T.TestCase):
    """Bare minimum setup to render and test templates"""
    __test__ = False

    authenticated = False

    @T.setup
    def setup_servlet(self):
        application = turtle.Turtle()
        application.settings = {
            'static_path':
            os.path.join(os.path.dirname(__file__), "../static"),
            'template_path':
            os.path.join(os.path.dirname(__file__), "../templates"),
            'autoescape':
            None,
        }

        # Properly load ui_modules and ui_methods
        application.ui_modules = {}
        application.ui_methods = {}
        application._load_ui_modules = types.MethodType(
            tornado.web.Application._load_ui_modules.im_func, application)
        application._load_ui_methods = types.MethodType(
            tornado.web.Application._load_ui_methods.im_func, application)
        application._load_ui_modules(ui_modules)
        application._load_ui_methods(ui_methods)

        if self.authenticated:
            application.settings['cookie_secret'] = 'cookie_secret'
        request = turtle.Turtle()
        self.servlet = RequestHandler(application, request)

    def render_etree(self, page, *args, **kwargs):
        self.servlet.render(page, *args, **kwargs)
        rendered_page = ''.join(self.servlet._write_buffer)
        tree = etree.HTML(rendered_page)
        return tree

    @contextmanager
    def no_ui_modules(self):
        modules = mock.Mock()
        modules.Request = mock.Mock()
        modules.NewRequestDialog = mock.Mock()
        with mock.patch.dict(self.servlet.ui, modules=modules):
            yield
Example #5
0
class TemplateTestCase(T.TestCase):
    """Bare minimum setup to render and test templates"""
    __test__ = False

    authenticated = False

    @T.setup
    def setup_servlet(self):
        application = turtle.Turtle()
        application.settings = {
            'static_path': os.path.join(os.path.dirname(__file__), "../static"),
            'template_path': os.path.join(os.path.dirname(__file__), "../templates"),
            'autoescape': None,
        }

        # Properly load ui_modules and ui_methods
        application.ui_modules = {}
        application.ui_methods = {}
        application._load_ui_modules = types.MethodType(tornado.web.Application._load_ui_modules.im_func, application)
        application._load_ui_methods = types.MethodType(tornado.web.Application._load_ui_methods.im_func, application)
        application._load_ui_modules(ui_modules)
        application._load_ui_methods(ui_methods)

        if self.authenticated:
            application.settings['cookie_secret'] = 'cookie_secret'
        request = turtle.Turtle()
        self.servlet = RequestHandler(application, request)

    def render_etree(self, page, *args, **kwargs):
        self.servlet.render(page, *args, **kwargs)
        rendered_page = ''.join(self.servlet._write_buffer)
        tree = etree.HTML(rendered_page)
        return tree

    @contextmanager
    def no_ui_modules(self):
        modules = mock.Mock()
        modules.Request = mock.Mock()
        modules.NewRequestDialog = mock.Mock()
        with mock.patch.dict(self.servlet.ui, modules=modules):
            yield
Example #6
0
    def setup_servlet(self):
        application = turtle.Turtle()
        application.settings = {
            'static_path': os.path.join(os.path.dirname(__file__), "../static"),
            'template_path': os.path.join(os.path.dirname(__file__), "../templates"),
            'autoescape': None,
        }

        # Properly load ui_modules and ui_methods
        application.ui_modules = {}
        application.ui_methods = {}
        application._load_ui_modules = types.MethodType(tornado.web.Application._load_ui_modules.im_func, application)
        application._load_ui_methods = types.MethodType(tornado.web.Application._load_ui_methods.im_func, application)
        application._load_ui_modules(ui_modules)
        application._load_ui_methods(ui_methods)

        if self.authenticated:
            application.settings['cookie_secret'] = 'cookie_secret'
        request = turtle.Turtle()
        self.servlet = RequestHandler(application, request)