本文整理汇总了Python中pyramid.testing.DummyRequest.static_url方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.static_url方法的具体用法?Python DummyRequest.static_url怎么用?Python DummyRequest.static_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.static_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_functional
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import static_url [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)
示例2: test_web_client_functionalities
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import static_url [as 别名]
def test_web_client_functionalities(self):
from pyramid.testing import DummyRequest
from c2cgeoportal.models import DBSession, User
from c2cgeoportal.tests.functional import mapserv_url
from c2cgeoportal.views.entry import Entry
request = DummyRequest()
request.static_url = lambda url: 'http://example.com/dummy/static/url'
request.route_url = lambda url: mapserv_url
request.user = None
request1 = DummyRequest()
request1.static_url = lambda url: 'http://example.com/dummy/static/url'
request1.route_url = lambda url: mapserv_url
request1.user = DBSession.query(User).filter(User.username == '__test_user1').one()
request2 = DummyRequest()
request2.static_url = lambda url: 'http://example.com/dummy/static/url'
request2.route_url = lambda url: mapserv_url
request2.user = DBSession.query(User).filter(User.username == '__test_user2').one()
settings = {
'functionalities': {
'anonymous': {
"__test_s": "anonymous",
"__test_a": ["a1", "a2"]
},
'registered': {
"__test_s": "registered",
"__test_a": ["r1", "r2"]
},
'available_in_templates': ['__test_s', '__test_a'],
},
'mapserv_url': mapserv_url,
}
request.registry.settings = settings
request1.registry.settings = settings
request2.registry.settings = settings
annon = Entry(request)._getVars()
u1 = Entry(request1)._getVars()
u2 = Entry(request2)._getVars()
self.assertEquals(annon['functionality'], {"__test_s": ["anonymous"], "__test_a": ["a1", "a2"]});
self.assertEquals(u1['functionality'], {"__test_s": ["registered"], "__test_a": ["r1", "r2"]});
self.assertEquals(u2['functionality'], {"__test_s": ["db"], "__test_a": ["db1", "db2"]});