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


Python Configurator.testing_add_template方法代码示例

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


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

示例1: test_handle_submit_key_expired

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import testing_add_template [as 别名]
    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:zagy,项目名称:karl,代码行数:31,代码来源:test_resetpassword.py

示例2: test_handle_submit_wrong_key

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import testing_add_template [as 别名]
    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:zagy,项目名称:karl,代码行数:27,代码来源:test_resetpassword.py

示例3: test___call__bad_key

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import testing_add_template [as 别名]
    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
        request.layout_manager = mock.Mock()
        # no key
        controller = self._makeOne(self.context, request)
        response = controller()
        from pyramid.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 pyramid.response import Response
        self.assertEqual(response.__class__, Response)
        self.failUnless(hasattr(renderer, 'api'))
        self.assertEqual(renderer.api.page_title,
                         'Password Reset URL Problem')
开发者ID:zagy,项目名称:karl,代码行数:30,代码来源:test_resetpassword.py

示例4: test_handle_submit_utf8_password

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import testing_add_template [as 别名]
 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:zagy,项目名称:karl,代码行数:29,代码来源:test_resetpassword.py

示例5: test_handle_submit

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import testing_add_template [as 别名]
 def test_handle_submit(self):
     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': 'secret'}
     import datetime
     keytime = datetime.datetime.now()
     profile.password_reset_time = keytime
     controller.handle_submit(converted)
     self.failUnless(hasattr(renderer, 'api'))
     self.assertEqual(renderer.api.page_title,
                      'Password Reset Complete')
     renderer.assert_(login='me', password='secret')
     self.failUnless(profile.password_reset_key is None)
     self.failUnless(profile.password_reset_time is None)
     user = self.context.users.get(login='me')
     from karl.models.users import pbkdf2
     self.assertEqual(user['password'], pbkdf2('secret', user['salt']))
开发者ID:lslaz1,项目名称:karl,代码行数:28,代码来源:test_resetpassword.py

示例6: test_handle_submit_bad_key

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import testing_add_template [as 别名]
 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)
     controller.handle_submit({})
     self.failUnless(hasattr(renderer, 'api'))
     self.assertEqual(renderer.api.page_title,
                      'Password Reset URL Problem')
开发者ID:zagy,项目名称:karl,代码行数:13,代码来源:test_resetpassword.py

示例7: registerDummyRenderer

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import testing_add_template [as 别名]
def registerDummyRenderer(path, renderer=None):
    """ Register a template renderer at ``path`` (usually a relative
    filename ala ``templates/foo.pt``) and return the renderer object.
    If the ``renderer`` argument is None, a 'dummy' renderer will be
    used.  This function is useful when testing code that calls the
    :func:`pyramid.renderers.render` function or
    :func:`pyramid.renderers.render_to_response` function or any
    other ``render_*`` or ``get_*`` API of the
    :mod:`pyramid.renderers` module.
    """
    registry = get_current_registry()
    config = Configurator(registry=registry)
    result = config.testing_add_template(path, renderer)
    config.commit()
    return result
开发者ID:araymund,项目名称:karl,代码行数:17,代码来源:testing.py

示例8: registerTemplateRenderer

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import testing_add_template [as 别名]
def registerTemplateRenderer(path, renderer=None):
    """ Register a template renderer at ``path`` (usually a relative
    filename ala ``templates/foo.pt``) and return the renderer object.
    If the ``renderer`` argument is None, a 'dummy' renderer will be
    used.  This function is useful when testing code that calls the
    :func:`pyramid.renderers.render` function or
    :func:`pyramid.renderers.render_to_response` function or any
    other ``render_*`` or ``get_*`` API of the
    :mod:`pyramid.renderers` module.

    .. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
       Instead use the
       :meth:`pyramid.config.Configurator.testing_add_template`
       method in your unit and integration tests.

    """
    registry = get_current_registry()
    config = Configurator(registry=registry)
    result = config.testing_add_template(path, renderer)
    config.commit()
    return result
开发者ID:jkrebs,项目名称:pyramid,代码行数:23,代码来源:testing.py

示例9: test_handle_submit

# 需要导入模块: from pyramid.config import Configurator [as 别名]
# 或者: from pyramid.config.Configurator import testing_add_template [as 别名]
    def test_handle_submit(self):
        context = self.context
        request = self.request

        # fake the mailer
        from repoze.sendmail.interfaces import IMailDelivery
        from karl.testing import DummyMailer
        mailer = DummyMailer()
        karl.testing.registerUtility(mailer, IMailDelivery)

        # fake catalog search
        from karl.models.interfaces import ICatalogSearch
        from zope.interface import Interface
        karl.testing.registerAdapter(
            DummyProfileSearch, (Interface,), ICatalogSearch)

        # fake a staff user
        from karl.testing import DummyUsers
        context.users = DummyUsers()
        context.users.add('me', 'me', 'password', ['group.KarlStaff'])

        # register dummy renderer for email template
        reg = get_current_registry()
        config = Configurator(reg, autocommit=True)
        renderer = config.testing_add_template(
            'templates/email_reset_password.pt')

        # test w/ staff user
        controller = self._makeOne(context, request)
        converted = {'email': '[email protected]'}
        response = controller.handle_submit(converted)
        self.failIf(len(mailer))
        self.assertEqual(response.location,
            'http://login.example.com/resetpassword?email=me%40example.com'
            '&came_from=http%3A%2F%2Fexample.com%2Flogin.html')

        # register dummy profile search
        profile_search = DummyProfileSearch(context)
        def search_adapter(context):
            return profile_search
        karl.testing.registerAdapter(
            search_adapter, (Interface,), ICatalogSearch)

        # convert to non-staff user and test again, email should
        # go out this time
        context.users._by_id['me']['groups'] = []
        response = controller.handle_submit(converted)
        self.assertEqual(response.location,
            'http://example.com/reset_sent.html?email=me%40example.com')
        profile = profile_search.profile
        self.failUnless(profile.password_reset_key)
        self.failUnless(profile.password_reset_time)
        self.assertEqual(len(mailer), 1)
        msg = mailer.pop()
        self.assertEqual(len(msg.mto), 1)
        self.assertEqual(msg.mto[0], '[email protected]')
        self.assertEqual(dict(msg.msg._headers)['Subject'],
                         'karl3test Password Reset Request')
        renderer.assert_(login='me', system_name='karl3test')
        self.failUnless(hasattr(renderer, 'reset_url'))
        self.failUnless(renderer.reset_url.startswith(
            'http://example.com/reset_confirm.html?key='), renderer.reset_url)
开发者ID:zagy,项目名称:karl,代码行数:64,代码来源:test_resetpassword.py


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