本文整理汇总了Python中horus.tests.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_register_existing_user
def test_register_existing_user(self):
from horus.views import RegisterController
from pyramid_mailer.mailer import DummyMailer
from pyramid_mailer.interfaces import IMailer
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.include('horus')
self.config.registry.registerUtility(DummyMailer(), IMailer)
self.config.add_route('index', '/')
admin = User(username='sontek', email='[email protected]')
admin.password = 'test123'
self.session.add(admin)
self.session.flush()
request = self.get_csrf_request(post={
'username': 'sontek',
'password': {
'password': 'test123',
'password-confirm': 'test123',
},
'email': '[email protected]'
}, request_method='POST')
view = RegisterController(request)
adict = view.register()
assert isinstance(adict, dict)
assert adict['errors']
示例2: test_inactive_login_fails
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')
示例3: test_forgot_password_valid_user
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 IUserClass
from horus.tests.models import User
self.config.registry.registerUtility(User, IUserClass)
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.password = 'foo'
self.session.add(user)
self.session.flush()
request = self.get_csrf_request(post={
'email': '[email protected]'
}, request_method='POST')
request.user = None
view = ForgotPasswordController(request)
with patch('horus.views.FlashMessage') as FlashMessage:
response = view.forgot_password()
FlashMessage.assert_called_with(request,
view.Str.reset_password_email_sent, kind="success")
assert response.status_int == 302
示例4: test_login_succeeds
def test_login_succeeds(self):
"""Make sure we can log in."""
from horus.tests.models import User
from horus.interfaces import IUserClass
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.registry.settings['horus.login_redirect'] = 'index'
self.config.registry.settings['horus.logout_redirect'] = 'index'
admin = User(username='sontek', email='[email protected]')
admin.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
示例5: test_profile_update_profile_invalid
def test_profile_update_profile_invalid(self):
from horus.views import ProfileController
from horus.interfaces import IUserClass
from horus.interfaces import IActivationClass
from horus.interfaces import IProfileSchema
from horus.tests.models import User
from horus.tests.models import Activation
from horus.tests.schemas import ProfileSchema
self.config.registry.registerUtility(Activation, IActivationClass)
self.config.registry.registerUtility(User, IUserClass)
self.config.registry.registerUtility(ProfileSchema,
IProfileSchema)
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()
request = self.get_csrf_request(request_method='POST')
request.context = user
request.matchdict = Mock()
get = Mock()
get.return_value = user.id
request.matchdict.get = get
view = ProfileController(request)
response = view.edit_profile()
assert len(response['errors']) == 3
示例6: test_activate_invalid
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 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.include('horus')
self.config.add_route('index', '/')
self.config.registry.registerUtility(DummyMailer(), IMailer)
user = User(username='sontek', email='[email protected]')
user.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
示例7: test_forgot_password_invalid_password
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 IUserClass
from horus.tests.models import User
self.config.registry.registerUtility(User, IUserClass)
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.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
示例8: test_inactive_login_fails
def test_inactive_login_fails(self):
"""Make sure we can't log in with an inactive user."""
from horus.tests.models import User
from horus.interfaces import IUserClass
from horus.interfaces import IActivationClass
from horus.tests.models import Activation
self.config.registry.registerUtility(Activation, IActivationClass)
self.config.registry.registerUtility(User, IUserClass)
user = User(username='sontek', email='[email protected]')
user.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')
self.config.registry.settings['horus.login_redirect'] = 'index'
self.config.registry.settings['horus.logout_redirect'] = 'index'
request = self.get_csrf_request(post={
'submit': True,
'username': 'sontek',
'password': 'foo',
}, request_method='POST')
view = AuthController(request)
with patch('horus.views.FlashMessage') as FlashMessage:
view.login()
FlashMessage.assert_called_with(request,
'Your account is not active, please check your e-mail.',
kind='danger')
示例9: test_valid_login
def test_valid_login(self):
""" Call the login view, make sure routes are working """
from horus.tests.models import User
admin = User(username='sontek', email='[email protected]')
admin.password = 'temp'
self.session.add(admin)
self.session.flush()
res = self.app.get('/login')
csrf = res.form.fields['csrf_token'][0].value
if six.PY3:
csrf = clean_byte_string(csrf)
res = self.app.post(
str('/login'),
{
'submit': True,
'username': 'sontek',
'password': 'temp',
'csrf_token': csrf
}
)
assert res.status_int == 302
示例10: test_forgot_password_valid_user
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 IUserClass
from horus.tests.models import User
self.config.registry.registerUtility(User, IUserClass)
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.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(
'Please check your e-mail to reset your password.', 'success')
assert response.status_int == 302
示例11: test_inactive_login
def test_inactive_login(self):
"""Make sure inactive users can't sign in."""
from horus.tests.models import User
from horus.tests.models import Activation
admin = User(username='sontek', email='[email protected]')
admin.activation = Activation()
admin.password = 'temp'
self.session.add(admin)
self.session.flush()
res = self.app.get('/login')
csrf = res.form.fields['csrf_token'][0].value
if six.PY3:
csrf = clean_byte_string(csrf)
res = self.app.post(
str('/login'),
{
'submit': True,
'username': 'sontek',
'password': 'temp',
'csrf_token': csrf
}
)
assert b'Your account is not active, please check your e-mail.' \
in res.body
示例12: test_profile_bad_id
def test_profile_bad_id(self):
from horus.views import ProfileController
from horus.interfaces import IUserClass
from horus.interfaces import IActivationClass
from horus.tests.models import User
from horus.tests.models import Activation
self.config.registry.registerUtility(User, IUserClass)
self.config.registry.registerUtility(Activation, IActivationClass)
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()
request = testing.DummyRequest()
request.user = Mock()
request.matchdict = Mock()
get = Mock()
get.return_value = 99
request.matchdict.get = get
view = ProfileController(request)
response = view.profile()
assert response.status_int == 404
示例13: test_password_hashing
def test_password_hashing(self):
from horus.tests.models import User
user1 = User(username='sontek', email='[email protected]')
user1.password = 'password'
self.session.add(user1)
self.session.flush()
assert user1.password != 'password'
assert user1.salt is not None
示例14: test_reset_password_valid_user
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
示例15: test_profile_update_password
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)