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


Python User.get_by_id方法代码示例

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


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

示例1: test_profile_update_password

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import get_by_id [as 别名]
    def test_profile_update_password(self):
        from horus.views import ProfileController
        from hem.interfaces import IDBSession
        from horus.events import ProfileUpdatedEvent
        from horus.models import crypt
        from horus.interfaces           import IUserClass
        from horus.tests.models         import User
        from horus.interfaces           import IActivationClass
        from horus.tests.models         import Activation
        self.config.registry.registerUtility(Activation, IActivationClass)

        self.config.registry.registerUtility(User, IUserClass)

        self.config.add_route('index', '/')
        self.config.include('horus')

        user = User(username='sontek', email='[email protected]')
        user.password = 'temp'

        self.session.add(user)
        self.session.flush()

        def handle_profile_updated(event):
            request = event.request
            session = request.registry.getUtility(IDBSession)
            session.commit()

        self.config.add_subscriber(handle_profile_updated,
            ProfileUpdatedEvent)

        request = self.get_csrf_request(post={
            'email': '[email protected]',
            'password': {
                'password': 'test123',
                'password-confirm': 'test123',
            },
        }, request_method='POST')

        request.context = user

        request.matchdict = Mock()
        get = Mock()
        get.return_value = user.id
        request.matchdict.get = get

        flash = Mock()
        request.session.flash = flash

        view = ProfileController(request)

        view.edit_profile()
        new_user = User.get_by_id(request, user.id)

        assert new_user.email == '[email protected]'
        assert not crypt.check(user.password, 'temp' + user.salt)
开发者ID:pzatrick,项目名称:horus,代码行数:57,代码来源:test_views.py

示例2: test_get_user_by_invalid_id

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import get_by_id [as 别名]
    def test_get_user_by_invalid_id(self):
        from horus.tests.models import User

        user = User(username='sontek', email='[email protected]')
        user.password = 'temp'
        self.session.add(user)
        self.session.commit()

        request = testing.DummyRequest()

        new_user = User.get_by_id(request, 2)

        assert new_user == None
开发者ID:Vigrond,项目名称:horus,代码行数:15,代码来源:test_models.py


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