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


Python User.get_by_user_name方法代码示例

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


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

示例1: test_activate_invalid_user

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import get_by_user_name [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(user_name='sontek', email='[email protected]')
        user.activation = Activation()
        user.set_password('foo')

        user2 = User(user_name='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.pk

        request.matchdict.get = get

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

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

示例2: test_activate_invalid

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import get_by_user_name [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(user_name='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_user_name(request, 'sontek')

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

示例3: test_register_creates_user

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import get_by_user_name [as 别名]
    def test_register_creates_user(self):
        from horus.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer
        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.registry.registerUtility(DummyMailer(), IMailer)

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

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

        request.user = Mock()
        controller = RegisterController(request)
        response = controller.register()

        assert response.status_int == 302

        user = User.get_by_user_name(request, 'admin')

        assert user != None
开发者ID:ccomb,项目名称:horus,代码行数:37,代码来源:test_views.py

示例4: test_register_no_email_validation

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import get_by_user_name [as 别名]
    def test_register_no_email_validation(self):
        from horus.views import RegisterController
        from pyramid_mailer.mailer import DummyMailer
        from pyramid_mailer.interfaces import IMailer
        from horus.interfaces import IHorusSession
        from horus.events import NewRegistrationEvent
        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.registry.registerUtility(DummyMailer(), IMailer)

        self.config.add_route('index', '/')
        self.config.registry.settings['su.require_activation'] = False

        def handle_registration(event):
            request = event.request
            session = request.registry.getUtility(IHorusSession)
            session.commit()

        self.config.add_subscriber(handle_registration, NewRegistrationEvent)


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

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

        request.user = Mock()

        controller = RegisterController(request)
        response = controller.register()

        assert response.status_int == 302

        user = User.get_by_user_name(request, 'admin')

        assert user.is_activated == True
        flash.assert_called_with('You have been registered, you may login now!', 'success')
开发者ID:ccomb,项目名称:horus,代码行数:53,代码来源:test_views.py

示例5: test_activate_multiple_users

# 需要导入模块: from horus.tests.models import User [as 别名]
# 或者: from horus.tests.models.User import get_by_user_name [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(user_name='sontek', email='[email protected]')
        user.activation = Activation()
        user.set_password('foo')
        user1 = User(user_name='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.pk

        request.matchdict.get = get

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

        activations = Activation.get_all(request)

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


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