本文整理汇总了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
示例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')
示例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)
示例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()
示例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
示例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')
示例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')
示例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
示例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')
示例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
示例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))
示例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')