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


Python configuration.Configurator类代码示例

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


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

示例1: TestRun

class TestRun(unittest.TestCase):
    def setUp(self):
        self.config = Configurator()
        self.config.begin()
        
    def tearDown(self):
        self.config.end()

    def test_app(self):
        from tattoo.run import app
        myapp = app(None, 
                    setup_db=setup_db, 
                    populate=populate, 
                    db_path='mongo://foo.com:1235/dbname',
                    min_url_len=21,
                    )
        self.assertEquals(myapp.__class__.__name__, 'Router')
        
    def test_app_without_db_string(self):
        from tattoo.run import app
        self.assertRaises(ValueError, app, 
                          None, 
                          setup_db=setup_db, 
                          populate=populate, 
                          min_url_len=21,
                          )

    def test_setup_db(self):
        from tattoo.run import setup_db
        from ming import Session
        from tattoo.models import SESSION_NAME
        db_uri = 'mongo://foo.com:1235/dbname'
        setup_db(db_uri)
        session = Session.by_name(SESSION_NAME)
        self.assertTrue(SESSION_NAME in session._registry.keys())
开发者ID:reedobrien,项目名称:tattoo,代码行数:35,代码来源:tests.py

示例2: test_handle_submit_key_expired

    def test_handle_submit_key_expired(self):
        reg = get_current_registry()
        config = Configurator(reg)
        renderer = config.testing_add_template('templates/reset_failed.pt')
        request = self.request
        request.params['key'] = '0' * 40
        self._setupUsers()
        context = self.context
        context['profiles'] = testing.DummyModel()
        profile = context['profiles']['me'] = testing.DummyModel()
        profile.password_reset_key = '0' * 40
        controller = self._makeOne(context, request)
        converted = {'login': 'me'}
        # first w/ no profile reset time
        response = controller.handle_submit(converted)
        self.failUnless(hasattr(renderer, 'api'))
        self.assertEqual(renderer.api.page_title,
                         'Password Reset Confirmation Key Expired')

        # now w/ expired key
        renderer = config.testing_add_template('templates/reset_failed.pt')
        from karl.views.resetpassword import max_reset_timedelta
        import datetime
        keytime = datetime.datetime.now() - max_reset_timedelta
        profile.password_reset_time = keytime
        response = controller.handle_submit(converted)
        self.failUnless(hasattr(renderer, 'api'))
        self.assertEqual(renderer.api.page_title,
                         'Password Reset Confirmation Key Expired')
开发者ID:cguardia,项目名称:karl,代码行数:29,代码来源:test_resetpassword.py

示例3: test_handle_submit_utf8_password

 def test_handle_submit_utf8_password(self):
     password = u'password\xe1'
     reg = get_current_registry()
     config = Configurator(reg)
     renderer = config.testing_add_template('templates/reset_complete.pt')
     request = self.request
     request.params['key'] = '0' * 40
     self._setupUsers()
     context = self.context
     context['profiles'] = testing.DummyModel()
     profile = context['profiles']['me'] = testing.DummyModel()
     profile.password_reset_key = '0' * 40
     controller = self._makeOne(context, request)
     converted = {'login': 'me', 'password': password}
     import datetime
     keytime = datetime.datetime.now()
     profile.password_reset_time = keytime
     response = controller.handle_submit(converted)
     self.failUnless(hasattr(renderer, 'api'))
     self.assertEqual(renderer.api.page_title,
                      'Password Reset Complete')
     renderer.assert_(login='me', password=password)
     self.failUnless(profile.password_reset_key is None)
     self.failUnless(profile.password_reset_time is None)
     user = self.context.users.get(login='me')
     from repoze.who.plugins.zodb.users import get_sha_password
     self.assertEqual(user['password'], get_sha_password(password.encode('utf8')))
开发者ID:cguardia,项目名称:karl,代码行数:27,代码来源:test_resetpassword.py

示例4: ModelUtilTests

class ModelUtilTests(unittest.TestCase):
    def setUp(self):
        self.config = Configurator()
        self.config.begin()

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

    def test_create_child_no_kwargs(self):
        from rfd.models import create_child
        class Thing(object):
            pass
        parent = Thing()
        name = "alice"
        child = create_child(Thing, parent, name)
        self.assertEqual(child.__parent__, parent)
        self.assertEqual(child.__name__, name)

    def test_create_child_with_kwargs(self):
        from rfd.models import create_child
        class Thing(object):
            pass
        parent = Thing()
        name = "alice"
        child = create_child(Thing, parent, name, foo="foo", bar="bar")
        self.assertEqual(child.__parent__, parent)
        self.assertEqual(child.__name__, name)
        self.assertEqual(child.foo, "foo")
        self.assertEqual(child.bar, "bar")
开发者ID:shentonfreude,项目名称:rfd,代码行数:29,代码来源:tests.py

示例5: test_handle_submit_wrong_key

    def test_handle_submit_wrong_key(self):
        reg = get_current_registry()
        config = Configurator(reg)
        renderer = config.testing_add_template('templates/reset_failed.pt')
        request = self.request
        request.params['key'] = '0' * 40
        self._setupUsers()
        context = self.context
        context['profiles'] = testing.DummyModel()
        context['profiles']['me'] = testing.DummyModel()
        controller = self._makeOne(context, request)
        converted = {'login': 'me'}
        # first w/ no profile reset key
        response = controller.handle_submit(converted)
        self.failUnless(hasattr(renderer, 'api'))
        self.assertEqual(renderer.api.page_title,
                         'Password Reset Confirmation Problem')

        # now w/ wrong profile reset key
        renderer = config.testing_add_template('templates/reset_failed.pt')
        context['profiles']['me'].password_reset_key = '1' * 40
        response = controller.handle_submit(converted)
        self.failUnless(hasattr(renderer, 'api'))
        self.assertEqual(renderer.api.page_title,
                         'Password Reset Confirmation Problem')
开发者ID:cguardia,项目名称:karl,代码行数:25,代码来源:test_resetpassword.py

示例6: test___call__bad_key

    def test___call__bad_key(self):
        # register dummy renderer for the email template
        reg = get_current_registry()
        config = Configurator(reg)
        renderer = config.testing_add_template('templates/reset_failed.pt')

        request = self.request
        # no key
        controller = self._makeOne(self.context, request)
        response = controller()
        from webob.response import Response
        self.assertEqual(response.__class__, Response)
        self.failUnless(hasattr(renderer, 'api'))
        self.assertEqual(renderer.api.page_title,
                         'Password Reset URL Problem')

        # reset renderer.api value so we know the test is useful
        renderer = config.testing_add_template('templates/reset_failed.pt')
        # key of wrong length
        request.params['key'] = 'foofoofoo'
        controller = self._makeOne(self.context, request)
        response = controller()
        from webob.response import Response
        self.assertEqual(response.__class__, Response)
        self.failUnless(hasattr(renderer, 'api'))
        self.assertEqual(renderer.api.page_title,
                         'Password Reset URL Problem')
开发者ID:cguardia,项目名称:karl,代码行数:27,代码来源:test_resetpassword.py

示例7: _registerComponents

 def _registerComponents(self):
     # Install a bit of configuration that make_app() usually
     # does for us.
     reg = get_current_registry()
     config = Configurator(reg)
     config.setup_registry()
     config.load_zcml('opencore.includes:configure.zcml')
开发者ID:junkafarian,项目名称:opencore,代码行数:7,代码来源:tests.py

示例8: CodecTests

class CodecTests(unittest.TestCase):
    def setUp(self):
        self.config = Configurator()
        self.config.begin()
    
    def tearDown(self):
        self.config.end()

    def _make_codec(self):
        from tattoo.codec import decode, encode, map_dict
        CHARS = u"ABC123.ä~€+"
        BASE = len(CHARS)
        map_dict.clear()
        for num in range(BASE):
            map_dict[num] = CHARS[num]
            map_dict[CHARS[num]] = num
        return decode, encode, map_dict

    def test_encode(self):
        decode, encode, map_dict = self._make_codec()
        self.assertEqual(encode(0), u'A')
        self.assertEqual(encode(10), u'+')
        self.assertEqual(encode(7), u'\xe4')
        self.assertEqual(encode(4), u'2')

    def test_decode(self):
        decode, encode, map_dict = self._make_codec()
        self.assertEqual(decode(u'A'), 0)
        self.assertEqual(decode(u'+'), 10)
        self.assertEqual(decode(u'\xe4'), 7)
        self.assertEqual(decode(u'2'), 4)
开发者ID:reedobrien,项目名称:tattoo,代码行数:31,代码来源:tests.py

示例9: app

def app(global_config, **settings):
    """ This function returns a WSGI application.
    
    It is usually called by the PasteDeploy framework during 
    ``paster serve``.
    """
    names = ('src_path', 'store_url', 'cache_url', 'max_entries', 'database', 'content_dir')
    values = []
    for name in names:
        val = settings.get(name)
        if val is None: 
            raise ValueError("No ’%s’ value in application configuration." % name) 
        values.append(val)
        
    src_path, store_url, cache_url, max_entries, database, content_dir = values
    
    zcml_file = settings.get('configure_zcml', 'configure.zcml')
    config = Configurator(settings=settings, root_factory=ContentRoot(content_dir))
    # use local component registry
    config.hook_zca()
    config.begin()
    config.load_zcml(zcml_file)
    
    register_source(src_path)
    register_store(store_url, cache_url, max_entries=max_entries)
    register_catalog(database)
    config.end()
    
    return config.make_wsgi_app()
开发者ID:vilos,项目名称:rstlibrary,代码行数:29,代码来源:run.py

示例10: _registerComponents

 def _registerComponents(self):
     # Install a bit of configuration that make_app() usually
     # does for us.
     reg = get_current_registry()
     config = Configurator(reg)
     config.setup_registry()
     config.load_zcml('karl.includes:configure.zcml')
     from zope.interface import Interface
     testing.registerAdapter(DummyToolAddables, (Interface, Interface),
                             IToolAddables)
开发者ID:cguardia,项目名称:karl,代码行数:10,代码来源:tests.py

示例11: maintenance

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,代码行数:10,代码来源:maintenance.py

示例12: test_handle_submit_bad_key

 def test_handle_submit_bad_key(self):
     reg = get_current_registry()
     config = Configurator(reg)
     renderer = config.testing_add_template('templates/reset_failed.pt')
     request = self.request
     request.params['key'] = 'foofoofoo'
     controller = self._makeOne(self.context, request)
     response = controller.handle_submit({})
     self.failUnless(hasattr(renderer, 'api'))
     self.assertEqual(renderer.api.page_title,
                      'Password Reset URL Problem')
开发者ID:cguardia,项目名称:karl,代码行数:11,代码来源:test_resetpassword.py

示例13: ViewIntegrationTest

class ViewIntegrationTest(ViewTest):
    def setUp(self):
        import seantisinvoice

        self.config = Configurator(package=seantisinvoice)
        self.config.begin()
        self.config.load_zcml("seantisinvoice:configure.zcml")
        _initTestingDB()

    def test_zcml_registration(self):
        pass
开发者ID:seantis,项目名称:seantisinvoice,代码行数:11,代码来源:tests.py

示例14: app

def app(global_config, **settings):
    """ This function returns a WSGI application.
    
    It is usually called by the PasteDeploy framework during 
    ``paster serve``.
    """
    config = Configurator()
    config.begin()
    config.add_view(home, renderer="templates/home.pt")
    config.add_view(expense, name='expense', renderer='templates/expense.pt')
    config.end()
    return config.make_wsgi_app()
开发者ID:shentonfreude,项目名称:fare,代码行数:12,代码来源:run.py

示例15: ViewTests

class ViewTests(unittest.TestCase):
    def setUp(self):
        self.config = Configurator()
        self.config.begin()

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

    def test_my_view(self):
        from bmibargains.views import my_view
        request = testing.DummyRequest()
        info = my_view(request)
        self.assertEqual(info['project'], 'bmibargains')
开发者ID:mitchellrj,项目名称:BMI-Bargains,代码行数:13,代码来源:tests.py


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