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


Python Configurator.add_route方法代码示例

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


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

示例1: maintenance

# 需要导入模块: from repoze.bfg.configuration import Configurator [as 别名]
# 或者: from repoze.bfg.configuration.Configurator import add_route [as 别名]
def maintenance(global_config, **local_conf):
    config = Configurator()
    config.begin()
    config.add_static_view('static', 'karl.views:static')
    config.add_route(name='maintenance',
                    path='/*url',
                    view=dummy_view,
                    view_renderer='down_for_maintenance.pt')
    config.end()
    return config.make_wsgi_app()
开发者ID:cguardia,项目名称:karl,代码行数:12,代码来源:maintenance.py

示例2: ViewTests

# 需要导入模块: from repoze.bfg.configuration import Configurator [as 别名]
# 或者: from repoze.bfg.configuration.Configurator import add_route [as 别名]
class ViewTests(unittest.TestCase):

    """ These tests are unit tests for the view.  They test the
    functionality of *only* the view.  They register and use dummy
    implementations of repoze.bfg functionality to allow you to avoid
    testing 'too much'"""

    def setUp(self):
        """ cleanUp() is required to clear out the application registry
        between tests (done in setUp for good measure too)
        """
        self.config = Configurator()
        self.config.begin()
        self.config.add_settings({'title' : 'Tattoo', 'description' : 'Another URL Shortener'})
        self.config.add_route(name='home', path='', request_method='GET')
        self.config.add_route(name='view', path=':short_url', request_method='GET')
        self.config.add_route(name='post', path ='', request_method='POST')
        self.config.add_route(name='put', path='', request_method='PUT')
        self.config.add_route(name='list', path='list', request_method='GET')
        self.config.add_route(name='nohead', path=':short_url', request_method='HEAD')
        self.config.add_static_view(name='static', path='templates/static', cache_max_age=0)
        self.config.scan()
        
    def tearDown(self):
        """ cleanUp() is required to clear out the application registry
        between tests
        """
        self.config.end()

    def _callFUT(self, context, request, view):
        return view(request)

    def test_home_view(self):
        from tattoo.views import home_view
        context = testing.DummyModel(title='Tattoo',
                                     description="URL Shortener")
        request = testing.DummyRequest()
        self._callFUT(context, request, home_view)
        view = home_view(request)
        self.assertEquals(view['title'], 'Tattoo')
        self.assertEquals(view['description'], "Another URL Shortener")
开发者ID:reedobrien,项目名称:tattoo,代码行数:43,代码来源:tests.py

示例3: ViewIntegrationTests

# 需要导入模块: from repoze.bfg.configuration import Configurator [as 别名]
# 或者: from repoze.bfg.configuration.Configurator import add_route [as 别名]
class ViewIntegrationTests(unittest.TestCase):
    def setUp(self):
        self.config = Configurator()
        self.config.begin()
        self.config.add_settings({'title' : 'Tattoo', 
                                  'description' : 'Another URL Shortener',
                                  'min_url_len': '21',
                                  'reload_templates' : False})
        self.config.add_route(name='home', path='', request_method='GET')
        self.config.add_route(name='view', path=':short_url', request_method='GET')
        self.config.add_route(name='post', path ='', request_method='POST')
        self.config.add_route(name='put', path='', request_method='PUT')
        self.config.add_route(name='list', path='list', request_method='GET')
        self.config.add_route(name='nohead', path=':short_url', request_method='HEAD')
        self.config.add_static_view(name='static', path='templates/static', cache_max_age=0)
        self.config.scan()

    def tearDown(self):
         self.config.end()

    def _make_request(self, dispatch):
        request = testing.DummyRequest(              
            url='AURL',
            environ={'HTTP_HOST': 'bfg.io:80'},
            matchdict= {'short_url': u'8K!kpD'},
            dispatch=dispatch)
        return request

    def test_url_view(self):
        from tattoo.views import url_view
        request = self._make_request(dispatch=None)
        result = url_view(request, URL=URL)
        self.assertEquals(result.status, '302 Found')
        self.assertEquals(result.headers['location'], 'AUrl')

    def test_url_not_found(self):
        from tattoo.views import url_view
        request = self._make_request(dispatch='test_stop_iteration')
        URL = DummyURL()
        URL.m.find = ModelURL({})
        URL.m.find.one = StopIteration
        result = url_view(request, URL=URL)
        self.assertEquals(result.status, '404 Not Found')
        self.assertEquals(result.body, '<h1>404 Not Found</h1> Nobody here but us fish...glug glug.')
        

    def test_post_view_new(self):
        from tattoo.views import create_post_view
        request = testing.DummyRequest(              
            url='http://bfg.io/create?url=http://example.com/somplace/really/long',
            environ={'HTTP_HOST': 'bfg.io:80'})
        result = create_post_view(request, url_factory=url_factory)
        self.assertEqual(result.status, '200 OK')

    def test_post_view_zero(self):
        from tattoo.views import create_post_view
        request = self._make_request(dispatch='test_zero')
        result = create_post_view(request, url_factory=url_factory)
        self.assertEqual(result.status, '412 Precondition Failed')

    def test_post_view_one(self):
        from tattoo.views import create_post_view
        request = self._make_request(dispatch='test_one')
        result = create_post_view(request, url_factory=url_factory)
        self.assertEqual(result.status, '303 See Other')

    def test_post_view_not_found(self):
        from tattoo.views import create_post_view
        request = self._make_request(dispatch='test_not_found')
        result = create_post_view(request, url_factory=url_factory)
        self.assertEqual(result.status, '404 Not Found')

    def test_post_view_precond_failed(self):
        from tattoo.views import create_post_view
        request = self._make_request(dispatch='test_precondfailed')
        result = create_post_view(request, url_factory=url_factory)
        self.assertEqual(result.status, '412 Precondition Failed')
        
    def test_post_view_too_short(self):
        from tattoo.views import create_post_view
        request = self._make_request(dispatch='test_too_short')
        result = create_post_view(request, url_factory=url_factory)
        self.assertEqual(result.status, '303 See Other')
        self.assertEqual(result.headers['location'], 'short')

    def test_put_view_integration(self):
        from tattoo.views import put_view
        request = testing.DummyRequest(              
            url='http://bfg.io/create?url=http://example.com/somplace/really/long',
            environ={'HTTP_HOST': 'bfg.io:80'})
        result = put_view(request, url_factory=url_factory)
        self.assertEqual(result.status, '201 Created')

    def test_put_view_zero(self):
        from tattoo.views import put_view
        request = self._make_request(dispatch='test_zero')
        result = put_view(request, url_factory=url_factory)
        self.assertEqual(result.status, '412 Precondition Failed')

    def test_put_view_one(self):
#.........这里部分代码省略.........
开发者ID:reedobrien,项目名称:tattoo,代码行数:103,代码来源:tests.py


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