本文整理汇总了Python中pyramid.testing.DummyRequest.registry方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.registry方法的具体用法?Python DummyRequest.registry怎么用?Python DummyRequest.registry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.registry方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_enabled
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_enabled(self):
request = DummyRequest()
request.session = {}
request.registry = DummyRegistry(google_analytics_code='1234')
ga = GoogleAnalytics(request)
self.assertTrue(ga.enabled)
request = DummyRequest()
request.session = {}
request.registry = DummyRegistry(google_analytics_code=None)
ga = GoogleAnalytics(request)
self.assertFalse(ga.enabled)
示例2: main
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def main(global_config, **settings):
""" This function returns a Pyramid WSGI application.
"""
config = Configurator(root_factory=getAppRoot, settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
# authnPolicy = BasicAuthAuthenticationPolicy(check=checkAuthentication,
# realm='Djosr Login') #, debug=True)
authnPolicy = AuthTktAuthenticationPolicy(secret='not telling',
callback=getGroups)#, debug=True)
authzPolicy = ACLAuthorizationPolicy()
config.set_authentication_policy(authnPolicy)
config.set_authorization_policy(authzPolicy)
sessFactory = UnencryptedCookieSessionFactoryConfig('not telling')
config.set_session_factory(sessFactory)
config.add_request_method(getUser, 'user', reify=True)
config.scan()
# this saves having to do a GET to catch simple bugs
# TODO remove later when code is bug-free ;-)
from pyramid.testing import DummyRequest
dummy = DummyRequest()
dummy.registry = config.registry
getAppRoot(dummy)
return config.make_wsgi_app()
示例3: test_context_lookup
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_context_lookup(self):
from pyramid_layout.config import add_panel
from pyramid_layout.layout import LayoutManager
from pyramid.config import Configurator
from pyramid.testing import DummyRequest
request = DummyRequest()
config = Configurator()
request.config = config
request.registry = config.registry
def panel_int(context, request):
return 'panel int %s' % context
def panel_str(context, request):
return 'panel str %s' % context
def panel_str_noname(context, request):
return 'panel str noname %s' % context
add_panel(config, panel_int, name='howdy', context=int)
add_panel(config, panel_str, name='howdy', context=str)
add_panel(config, panel_str_noname)
config.commit()
self.assertEqual(LayoutManager(1, request).render_panel('howdy'), 'panel int 1')
self.assertEqual(LayoutManager(1, request).render_panel('howdy', context='1'), 'panel str 1')
self.assertEqual(LayoutManager('2', request).render_panel('howdy'), 'panel str 2')
self.assertEqual(LayoutManager('2', request).render_panel('howdy', context=2), 'panel int 2')
self.assertEqual(LayoutManager('2', request).render_panel(), 'panel str noname 2')
示例4: test_set_resource_route_name
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_set_resource_route_name():
config = Configurator()
config.scan('resource_route_name')
config.make_wsgi_app()
request = DummyRequest()
request.registry = config.registry
assert request.route_path('user', id=15) == '/users/15'
示例5: test_registerView_withresult
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_registerView_withresult(self):
from pyramid import testing
view = testing.registerView('moo.html', 'yo')
import types
self.failUnless(isinstance(view, types.FunctionType))
from pyramid.view import render_view_to_response
request = DummyRequest()
request.registry = self.registry
response = render_view_to_response(None, request, 'moo.html')
self.assertEqual(response.body, 'yo')
示例6: test_registerView_defaults
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_registerView_defaults(self):
from pyramid import testing
view = testing.registerView('moo.html')
import types
self.assertTrue(isinstance(view, types.FunctionType))
from pyramid.view import render_view_to_response
request = DummyRequest()
request.registry = self.registry
response = render_view_to_response(None, request, 'moo.html')
self.assertEqual(view(None, None).body, response.body)
示例7: test_registerView_custom
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_registerView_custom(self):
from pyramid import testing
def view(context, request):
from webob import Response
return Response('123')
view = testing.registerView('moo.html', view=view)
import types
self.failUnless(isinstance(view, types.FunctionType))
from pyramid.view import render_view_to_response
request = DummyRequest()
request.registry = self.registry
response = render_view_to_response(None, request, 'moo.html')
self.assertEqual(response.body, '123')
示例8: test_registerView_with_permission_allowing
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_registerView_with_permission_allowing(self):
from pyramid import testing
def view(context, request):
from webob import Response
return Response('123')
view = testing.registerView('moo.html', view=view, permission='bar')
testing.registerDummySecurityPolicy(permissive=True)
import types
self.failUnless(isinstance(view, types.FunctionType))
from pyramid.view import render_view_to_response
request = DummyRequest()
request.registry = self.registry
result = render_view_to_response(None, request, 'moo.html')
self.assertEqual(result.app_iter, ['123'])
示例9: test_registerView_with_permission_denying
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_registerView_with_permission_denying(self):
from pyramid import testing
from pyramid.exceptions import Forbidden
def view(context, request):
""" """
view = testing.registerView('moo.html', view=view, permission='bar')
testing.registerDummySecurityPolicy(permissive=False)
import types
self.failUnless(isinstance(view, types.FunctionType))
from pyramid.view import render_view_to_response
request = DummyRequest()
request.registry = self.registry
self.assertRaises(Forbidden, render_view_to_response,
None, request, 'moo.html')
示例10: test_login_update_join
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_login_update_join(self):
from ptahcrowd import login
request = DummyRequest()
request.registry = self.registry
cfg = ptah.get_settings(ptahcrowd.CFG_ID_CROWD, self.registry)
cfg["join"] = True
cfg["join-url"] = ""
form = login.LoginForm(None, request)
form.update()
self.assertTrue(form.join)
self.assertEqual(form.joinurl, "http://example.com/join.html")
示例11: test_functional
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_functional(self):
from pyramid.config import Configurator
from pyramid.testing import DummyRequest
import pkg_resources
version = pkg_resources.get_distribution('van.static').version
config = Configurator(autocommit=True)
config.include('van.static.cdn')
config.add_cdn_view('http://cdn.example.com/path', 'van.static:static_files')
config.add_cdn_view('name1', 'package1:path1')
req = DummyRequest()
req.registry = config.registry
# req.static_url actually generates the right urls
self.assertEqual(req.static_url('package1:path1/path2'), 'http://example.com/name1/path2')
self.assertEqual(req.static_url('van.static:static_files/file1.js'), 'http://cdn.example.com/path/van.static/%s/static_files/file1.js' % version)
示例12: test_get_file_storage
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import registry [as 别名]
def test_get_file_storage():
from pyramid_storage import registry
from pyramid_storage.interfaces import IFileStorage
@implementer(IFileStorage)
class DummyFileStorage(object):
pass
settings = {
'storage.base_path': 'uploads',
}
with testConfig(settings=settings) as config:
fs = DummyFileStorage()
req = DummyRequest()
req.registry = config.registry
registry.register_file_storage_impl(config, fs)
impl = registry.get_file_storage_impl(req)
assert impl == fs