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


Python User.set_password方法代码示例

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


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

示例1: test_activate_invalid

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_activate_invalid(self):
        from horus.views import RegisterController
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from horus.interfaces           import IHorusUserClass
        from horus.tests.models         import User
        from horus.interfaces           import IHorusActivationClass
        from horus.tests.models         import Activation
        self.config.registry.registerUtility(Activation, IHorusActivationClass)

        self.config.registry.registerUtility(User, IHorusUserClass)
        self.config.include('horus')
        self.config.add_route('index', '/')

        self.config.registry.registerUtility(DummyMailer(), IMailer)

        user = User(username='sontek', email='[email protected]')
        user.set_password('temp')
        user.activation = Activation()

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

        request = testing.DummyRequest()
        request.matchdict = Mock()
        get = Mock()
        get.return_value = 'invalid'
        request.matchdict.get = get

        controller = RegisterController(request)
        response = controller.activate()
        user = User.get_by_username(request, 'sontek')

        assert not user.is_activated
        assert response.status_int == 404
开发者ID:zerotired,项目名称:horus,代码行数:37,代码来源:test_views.py

示例2: test_forgot_password_invalid_password

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_forgot_password_invalid_password(self):
        from horus.views import ForgotPasswordController
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from horus.interfaces           import IHorusUserClass
        from horus.tests.models         import User

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

        self.config.add_route('index', '/')
        self.config.include('horus')
        self.config.registry.registerUtility(DummyMailer(), IMailer)

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

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

        request = self.get_csrf_request(post={
            'Email': 'sontek'
        }, request_method='POST')

        request.user = None

        view = ForgotPasswordController(request)
        response = view.forgot_password()

        assert len(response['errors']) == 1
开发者ID:zerotired,项目名称:horus,代码行数:31,代码来源:test_views.py

示例3: test_forgot_password_valid_user

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_forgot_password_valid_user(self):
        from horus.views import ForgotPasswordController
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from horus.interfaces           import IHorusUserClass
        from horus.tests.models         import User

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

        self.config.add_route('index', '/')
        self.config.include('horus')
        self.config.registry.registerUtility(DummyMailer(), IMailer)

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

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


        request = self.get_csrf_request(post={
            'Email': '[email protected]'
        }, request_method='POST')

        request.user = None

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

        view = ForgotPasswordController(request)
        response = view.forgot_password()

        flash.assert_called_with(u'Please check your e-mail to reset your password.', 'success')
        assert response.status_int == 302
开发者ID:zerotired,项目名称:horus,代码行数:36,代码来源:test_views.py

示例4: test_login_succeeds

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_login_succeeds(self):
        """ Make sure we can login """
        from horus.tests.models import User
        from horus.interfaces     import IHorusUserClass
        from horus.interfaces   import IHorusActivationClass
        from horus.tests.models import Activation
        self.config.registry.registerUtility(Activation, IHorusActivationClass)

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

        admin = User(username='sontek', email='[email protected]')
        admin.set_password('foo')

        self.session.add(admin)
        self.session.flush()

        from horus.views import AuthController
        self.config.add_route('index', '/')

        self.config.include('horus')

        request = self.get_csrf_request(post={
                'submit': True,
                'Username': 'sontek',
                'Password': 'foo',
            }, request_method='POST')

        view = AuthController(request)
        response = view.login()

        assert response.status_int == 302
开发者ID:zerotired,项目名称:horus,代码行数:33,代码来源:test_views.py

示例5: test_inactive_login_fails

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_inactive_login_fails(self):
        """ Make sure we can't login with an inactive user """
        from horus.tests.models import User
        from horus.interfaces     import IHorusUserClass
        from horus.interfaces   import IHorusActivationClass
        from horus.tests.models import Activation
        self.config.registry.registerUtility(Activation, IHorusActivationClass)

        self.config.registry.registerUtility(User, IHorusUserClass)
        user = User(username='sontek', email='[email protected]')
        user.set_password('foo')
        user.activation = Activation()
        self.session.add(user)
        self.session.flush()

        from horus.views import AuthController
        self.config.add_route('index', '/')
        self.config.include('horus')

        request = self.get_csrf_request(post={
                'submit': True,
                'Username': 'sontek',
                'Password': 'foo',
            }, request_method='POST')

        flash = Mock()

        request.session.flash = flash

        view = AuthController(request)
        view.login()

        flash.assert_called_with(u'Your account is not active, please check your e-mail.',
            'error')
开发者ID:zerotired,项目名称:horus,代码行数:36,代码来源:test_views.py

示例6: test_profile_bad_pk

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_profile_bad_pk(self):
        from horus.views import ProfileController
        from horus.interfaces           import IHorusUserClass
        from horus.interfaces           import IHorusActivationClass
        from horus.tests.models         import User
        from horus.tests.models         import Activation

        self.config.registry.registerUtility(User, IHorusUserClass)
        self.config.registry.registerUtility(Activation, IHorusActivationClass)

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

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

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

        request = testing.DummyRequest()
        request.user = Mock()

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

        request.matchdict = Mock()
        get = Mock()
        get.return_value = 99
        request.matchdict.get = get

        view = ProfileController(request)

        response = view.profile()

        assert response.status_int == 404
开发者ID:zerotired,项目名称:horus,代码行数:37,代码来源:test_views.py

示例7: test_password_hashing

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_password_hashing(self):
        from horus.tests.models import User
        user1 = User(user_name='sontek', email='[email protected]')
        user1.set_password('password')
        self.session.add(user1)
        self.session.flush()

        assert user1.password != 'password'
        assert user1.salt != None
开发者ID:ccomb,项目名称:horus,代码行数:11,代码来源:test_models.py

示例8: test_reset_password_valid_user

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_reset_password_valid_user(self):
        from horus.views import ForgotPasswordController
        from hem.interfaces import IDBSession
        from horus.events import PasswordResetEvent
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from horus.models import crypt
        from horus.interfaces           import IHorusUserClass
        from horus.interfaces           import IHorusActivationClass
        from horus.tests.models         import User
        from horus.tests.models         import Activation

        self.config.registry.registerUtility(User, IHorusUserClass)
        self.config.registry.registerUtility(Activation, IHorusActivationClass)


        self.config.add_route('index', '/')
        self.config.include('horus')
        self.config.registry.registerUtility(DummyMailer(), IMailer)

        user = User(username='sontek', email='[email protected]')
        user.set_password('foo')
        user.activation = Activation()

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

        request = self.get_csrf_request(post={
            'Password': {
                'Password': 'test123',
                'Password-confirm': 'test123',
            },
        }, request_method='POST')

        request.matchdict = Mock()
        get = Mock()
        get.return_value = user.activation.code
        request.matchdict.get = get

        request.user = None

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

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

        self.config.add_subscriber(handle_password_reset, PasswordResetEvent)

        view = ForgotPasswordController(request)
        response = view.reset_password()

        assert not crypt.check(user.password, 'temp' + user.salt)
        assert response.status_int == 302
开发者ID:zerotired,项目名称:horus,代码行数:58,代码来源:test_views.py

示例9: test_profile_update_password

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [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 IHorusUserClass
        from horus.tests.models         import User
        from horus.interfaces           import IHorusActivationClass
        from horus.tests.models         import Activation
        self.config.registry.registerUtility(Activation, IHorusActivationClass)

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

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

        user = User(username='sontek', email='[email protected]')
        user.set_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:zerotired,项目名称:horus,代码行数:57,代码来源:test_views.py

示例10: test_acl

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_acl(self):
        from horus.tests.models import User
        from pyramid.security import Allow

        user1 = User(user_name='sontek', email='[email protected]')
        user1.set_password('foo')

        self.session.add(user1)
        self.session.flush()

        assert user1.__acl__ == [(Allow, 'user:%s' % user1.pk, 'access_user')]
开发者ID:ccomb,项目名称:horus,代码行数:13,代码来源:test_models.py

示例11: test_activate_invalid_user

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_activate_invalid_user(self):
        from horus.views import RegisterController
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from horus.interfaces           import IHorusUserClass
        from horus.tests.models         import User
        from horus.interfaces           import IHorusActivationClass
        from horus.tests.models         import Activation
        self.config.registry.registerUtility(Activation, IHorusActivationClass)

        self.config.registry.registerUtility(User, IHorusUserClass)
        self.config.include('horus')
        self.config.add_route('index', '/')

        self.config.registry.registerUtility(DummyMailer(), IMailer)

        bad_act = Activation()

        user = User(username='sontek', email='[email protected]')
        user.activation = Activation()
        user.set_password('foo')

        user2 = User(username='jessie', email='[email protected]')
        user2.activation = bad_act
        user2.set_password('foo2')

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

        request = testing.DummyRequest()
        request.matchdict = Mock()

        def get(val, ret):
            if val == 'code':
                return bad_act.code
            elif val == 'user_pk':
                return user.id

        request.matchdict.get = get

        controller = RegisterController(request)
        response = controller.activate()
        new_user1 = User.get_by_username(request, 'sontek')
        new_user2 = User.get_by_username(request, 'jessie')

        assert not new_user1.is_activated
        assert not new_user2.is_activated
        assert response.status_int == 404
开发者ID:zerotired,项目名称:horus,代码行数:51,代码来源:test_views.py

示例12: test_activate_multiple_users

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_activate_multiple_users(self):
        from horus.views import RegisterController
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from horus.interfaces           import IHorusUserClass
        from horus.tests.models         import User
        from horus.interfaces           import IHorusActivationClass
        from horus.tests.models         import Activation
        self.config.registry.registerUtility(Activation, IHorusActivationClass)

        self.config.registry.registerUtility(User, IHorusUserClass)
        self.config.include('horus')
        self.config.add_route('index', '/')

        self.config.registry.registerUtility(DummyMailer(), IMailer)

        user = User(username='sontek', email='[email protected]')
        user.activation = Activation()
        user.set_password('foo')
        user1 = User(username='sontek1', email='[email protected]')
        user1.activation = Activation()
        user1.set_password('foo2')

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

        request = testing.DummyRequest()
        request.matchdict = Mock()

        def get(key, default):
            if key == 'code':
                return user1.activation.code
            else:
                return user1.id

        request.matchdict.get = get

        controller = RegisterController(request)
        response = controller.activate()
        user = User.get_by_username(request, 'sontek1')

        activations = Activation.get_all(request)

        assert len(activations.all()) == 1
        assert user.is_activated
        assert response.status_int == 302
开发者ID:zerotired,项目名称:horus,代码行数:49,代码来源:test_views.py

示例13: test_reset_password_invalid_password

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_reset_password_invalid_password(self):
        from horus.views import ForgotPasswordController
        from pyramid_mailer.interfaces import IMailer
        from pyramid_mailer.mailer import DummyMailer
        from horus.interfaces           import IHorusUserClass
        from horus.interfaces           import IHorusActivationClass
        from horus.tests.models         import User
        from horus.tests.models         import Activation

        self.config.registry.registerUtility(User, IHorusUserClass)
        self.config.registry.registerUtility(Activation, IHorusActivationClass)

        self.config.add_route('index', '/')
        self.config.include('horus')
        self.config.registry.registerUtility(DummyMailer(), IMailer)


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

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

        request = self.get_csrf_request(post={
            'Password': {
                'Password': 't',
                'Password-confirm': 't',
            },
        }, request_method='POST')

        request.matchdict = Mock()
        get = Mock()
        get.return_value = user.activation.code
        request.matchdict.get = get

        request.user = None

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

        view = ForgotPasswordController(request)
        response = view.reset_password()

        assert len(response['errors']) == 1
开发者ID:zerotired,项目名称:horus,代码行数:47,代码来源:test_views.py

示例14: test_user_factory

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import set_password [as 别名]
    def test_user_factory(self):
        from horus.resources import UserFactory
        from horus.tests.models import User
        from horus.interfaces import IHorusUserClass
        self.config.registry.registerUtility(User, IHorusUserClass)

        user = User(user_name='sontek', email='[email protected]')
        user.set_password('foo')
        self.session.add(user)
        self.session.commit()

        request = testing.DummyRequest()
        factory = UserFactory(request)

        fact_user = factory[user.pk]

        assert factory.request == request
        assert user == fact_user
开发者ID:ccomb,项目名称:horus,代码行数:20,代码来源:test_resources.py

示例15: test_group_finder

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

        group = Group(name='foo', description='bar')
        user1 = User(username='sontek', email='[email protected]')
        user1.set_password('foo')
        group.users.append(user1)

        self.session.add(group)
        self.session.add(user1)
        self.session.flush()

        request = Mock()
        request.user = user1

        results = groupfinder(1, request)

        assert 'group:foo' in results
        assert 'user:%s' % (user1.id) in results
        assert len(results) == 2
开发者ID:zerotired,项目名称:horus,代码行数:24,代码来源:test_init.py


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