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


Python DummyRequest.static_url方法代码示例

本文整理汇总了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)
开发者ID:jinty,项目名称:van.static,代码行数:16,代码来源:test_cdn.py

示例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"]});
开发者ID:bbinet,项目名称:c2cgeoportal,代码行数:45,代码来源:test_functionalities.py


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