当前位置: 首页>>代码示例>>Python>>正文


Python DummyRequest.root方法代码示例

本文整理汇总了Python中pyramid.testing.DummyRequest.root方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.root方法的具体用法?Python DummyRequest.root怎么用?Python DummyRequest.root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyramid.testing.DummyRequest的用法示例。


在下文中一共展示了DummyRequest.root方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __setup_thelma

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
 def __setup_thelma(self, ini_file):
     here_dir = os.getcwd()
     config_uri = 'config:%s' % ini_file
     self.logging_file_config(ini_file) # pylint: disable=E1101
     settings = appconfig(config_uri, 'thelma', relative_to=here_dir)
     reg = Registry('thelma')
     # Some tools need to resolve URLs, so we need to set up a request
     # and a service.
     url = 'http://0.0.0.0:6543'
     req = DummyRequest(application_url=url,
                        host_url=url,
                        path_url=url,
                        url=url,
                        registry=reg)
     config = create_config(settings, registry=reg)
     config.setup_registry(settings=settings)
     config.begin(request=req)
     config.load_zcml('configure.zcml')
     srvc = config.get_registered_utility(IService)
     req.root = srvc
     # Set up repositories.
     repo_mgr = config.get_registered_utility(IRepositoryManager)
     repo_mgr.initialize_all()
     # Start the everest service.
     srvc.start()
     # Configure the session maker.
     session_maker.configure(extension=ZopeTransactionExtension())
     # Set up machinery to enforce a session.flush() just before the
     # report is run so we have proper IDs in the output.
     # FIXME: This should be encapsulated better, perhaps depending on
     #        an option that selects the backend.
     def on_session_begin(session, trx, conn): # pylint: disable=W0613
         self._report_callback = lambda sess = session: sess.flush()
     event.listen(Session, 'after_begin', on_session_begin)
     return config
开发者ID:helixyte,项目名称:TheLMA,代码行数:37,代码来源:shell.py

示例2: test_forbidden

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
    def test_forbidden(self):
        from ptahcrowd.forbidden import Forbidden

        class Context(object):
            """ """

        request = DummyRequest()
        request.url = 'http://example.com'
        request.application_url = 'http://example.com'
        request.root = Context()

        excview = Forbidden(HTTPForbidden(), request)
        excview.update()

        res = request.response

        self.assertIs(excview.__parent__, request.root)
        self.assertEqual(res.status, '302 Found')
        self.assertEqual(
            text_(res.headers['location']),
            'http://example.com/login.html?came_from=http%3A%2F%2Fexample.com')

        excview = Forbidden(HTTPForbidden(), request)
        res = excview()
        self.assertEqual(res.status, '302 Found')
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:27,代码来源:test_forbidden.py

示例3: setUp

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
    def setUp(self):
        import tempfile
        import os.path
        self.tmpdir = tempfile.mkdtemp()
        dbpath = os.path.join( self.tmpdir, 'test.db')
        uri = 'file://' + dbpath
        settings = {'zodbconn.uri': uri,
                    'substanced.secret': 'sosecret',
                    'substanced.initial_login': 'admin',
                    'substanced.initial_password': 'admin',
                    'pyramid.includes': [
                        'substanced',
                        'pyramid_chameleon',
                        'pyramid_layout',
                        'pyramid_mailer.testing', # have to be after substanced to override the mailer
                        'pyramid_tm',
                        'dace',
                        'pontus',
        ]}

        app = main({}, **settings)
        self.db = app.registry._zodb_databases['']
        request = DummyRequest()
        testing.setUp(registry=app.registry, request=request)
        self.app = root_factory(request)
        request.root = self.app
        from webtest import TestApp
        self.testapp = TestApp(app)
        self.request = request
        import time; time.sleep(2)
开发者ID:ecreall,项目名称:pontus,代码行数:32,代码来源:testing.py

示例4: execute_callback

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
def execute_callback(app, callback, login):
    # set site and interaction that will be memorized in job
    request = DummyRequest()
    request.root = app
    registry = get_current_registry()
    manager.push({'registry': registry, 'request': request})
    user = get_user_by_login(login, request)
    request.user = user
    callback()
    manager.pop()
开发者ID:ecreall,项目名称:dace,代码行数:12,代码来源:util.py

示例5: setUp

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
 def setUp(self):
     registry = get_current_registry()
     db = registry._zodb_databases[self.database_name]
     app = db.open().root()[self.site_id]
     request = DummyRequest()
     request.root = app
     manager.push({'registry': registry, 'request': request})
     user = get_user_by_userid(self.userid)
     request.user = user
     return app
开发者ID:ecreall,项目名称:dace,代码行数:12,代码来源:util.py

示例6: test_not_found

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
    def test_not_found(self):
        from ptah.exc import NotFound

        class Context(object):
            """ """

        request = DummyRequest()
        request.root = Context()

        excview = NotFound(HTTPNotFound(), request)
        excview.update()

        self.assertIs(excview.__parent__, request.root)
        self.assertEqual(request.response.status, '404 Not Found')
开发者ID:blaflamme,项目名称:ptah,代码行数:16,代码来源:test_exc.py

示例7: test_forbidden_user

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
    def test_forbidden_user(self):
        from ptah.exc import Forbidden
        self._init_ptah()
        config.start(self.p_config)

        class Context(object):
            """ """
            __name__ = 'test'

        request = DummyRequest()
        request.root = Context()
        ptah.authService.set_userid('user')

        res = Forbidden.__renderer__(HTTPForbidden(), request)
        self.assertEqual(res.status, '403 Forbidden')
开发者ID:blaflamme,项目名称:ptah,代码行数:17,代码来源:test_exc.py

示例8: __enter__

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
 def __enter__(self):
     request = DummyRequest(application_url=self.__ini.app_url,
                            host_url=self.__ini.app_url,
                            path_url=self.__ini.app_url,
                            url=self.__ini.app_url,
                            registry=self.__config.registry)
     srvc = self.__config.get_registered_utility(IService)
     self.__config.begin(request=request)
     request.root = srvc
     repo_mgr = self.__config.get_registered_utility(IRepositoryManager)
     repo_mgr.initialize_all()
     if not self.__ini.app_name is None:
         plugin_mgr = self.__config.get_registered_utility(IPluginManager)
         plugin_mgr.load_all("%s.plugins" % self.__ini.app_name)
     srvc.start()
     if self.__repo_name is None:
         repo = repo_mgr.get_default()
     else:
         repo = repo_mgr.get(self.__repo_name)
     return repo
开发者ID:helixyte,项目名称:everest,代码行数:22,代码来源:fixtures.py

示例9: test_forbidden_custom_login

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
    def test_forbidden_custom_login(self):
        from ptah.exc import Forbidden

        class Context(object):
            """ """

        request = DummyRequest()
        request.url = u'http://example.com'
        request.root = Context()
        ptah.PTAH_CONFIG.login = '/custom-login.html'

        excview = Forbidden(HTTPForbidden(), request)
        excview.update()

        res = request.response

        self.assertIs(excview.__parent__, request.root)
        self.assertEqual(res.status, '302 Found')
        self.assertEqual(
            res.headers['location'],
            'http://example.com/custom-login.html?came_from=http%3A%2F%2Fexample.com')
开发者ID:blaflamme,项目名称:ptah,代码行数:23,代码来源:test_exc.py

示例10: test_addform_add

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
    def test_addform_add(self):
        from ptah.cms.forms import AddForm
        ptah.authService.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(
            POST = {'title': 'Test Content',
                    'form.buttons.add': 'Add'})
        request.root = container
        request.root.__path__ = '/'
        request.root.__root_path__ = '/'

        form = AddForm(container, request)

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__

        try:
            form.update()
        except Exception, res:
            pass
开发者ID:blaflamme,项目名称:ptah,代码行数:23,代码来源:test_forms.py

示例11: test_addform_add

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
    def test_addform_add(self):
        from ptah.cms.forms import AddForm
        ptah.auth_service.set_userid(ptah.SUPERUSER_URI)

        container = Container()
        request = DummyRequest(
            POST = {'title': 'Test Content',
                    'form.buttons.add': 'Add'})
        request.root = container
        request.root.__path__ = '/'
        request.root.__root_path__ = '/'

        form = AddForm(container, request)

        Content.__type__.permission = ptah.cms.NO_PERMISSION_REQUIRED
        form.tinfo = Content.__type__

        res = form.update()

        self.assertIsInstance(res, HTTPFound)
        self.assertEqual(res.headers['location'], '/test-content/')
        self.assertIn('New content has been created.',
                      ptah.view.render_messages(request))
开发者ID:runyaga,项目名称:ptah,代码行数:25,代码来源:test_forms.py

示例12: test_forbidden_custom_login

# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import root [as 别名]
    def test_forbidden_custom_login(self):
        import ptahcrowd
        from ptahcrowd.forbidden import Forbidden

        class Context(object):
            """ """

        request = DummyRequest()
        request.url = 'http://example.com'
        request.root = Context()

        CFG = ptah.get_settings(ptahcrowd.CFG_ID_CROWD, self.registry)
        CFG['login-url'] = '/custom-login.html'

        excview = Forbidden(HTTPForbidden(), request)
        excview.update()

        res = request.response

        self.assertIs(excview.__parent__, request.root)
        self.assertEqual(res.status, '302 Found')
        self.assertEqual(
            text_(res.headers['location']),
            'http://example.com/custom-login.html?came_from=http%3A%2F%2Fexample.com')
开发者ID:webmaven,项目名称:ptahcrowd,代码行数:26,代码来源:test_forbidden.py


注:本文中的pyramid.testing.DummyRequest.root方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。