本文整理汇总了Python中repoze.bfg.configuration.Configurator.add_static_view方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.add_static_view方法的具体用法?Python Configurator.add_static_view怎么用?Python Configurator.add_static_view使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类repoze.bfg.configuration.Configurator
的用法示例。
在下文中一共展示了Configurator.add_static_view方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: maintenance
# 需要导入模块: from repoze.bfg.configuration import Configurator [as 别名]
# 或者: from repoze.bfg.configuration.Configurator import add_static_view [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()
示例2: ViewTests
# 需要导入模块: from repoze.bfg.configuration import Configurator [as 别名]
# 或者: from repoze.bfg.configuration.Configurator import add_static_view [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")
示例3: ViewIntegrationTests
# 需要导入模块: from repoze.bfg.configuration import Configurator [as 别名]
# 或者: from repoze.bfg.configuration.Configurator import add_static_view [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):
#.........这里部分代码省略.........