本文整理汇总了Python中horus.views.RegisterController.activate方法的典型用法代码示例。如果您正苦于以下问题:Python RegisterController.activate方法的具体用法?Python RegisterController.activate怎么用?Python RegisterController.activate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horus.views.RegisterController
的用法示例。
在下文中一共展示了RegisterController.activate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_activate_invalid
# 需要导入模块: from horus.views import RegisterController [as 别名]
# 或者: from horus.views.RegisterController import activate [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 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
示例2: test_activate_invalid_user
# 需要导入模块: from horus.views import RegisterController [as 别名]
# 或者: from horus.views.RegisterController import activate [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 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)
bad_act = Activation()
user = User(username='sontek', email='[email protected]')
user.activation = Activation()
user.password = 'foo'
user2 = User(username='jessie', email='[email protected]')
user2.activation = bad_act
user2.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_id':
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
示例3: test_activate_multiple_users
# 需要导入模块: from horus.views import RegisterController [as 别名]
# 或者: from horus.views.RegisterController import activate [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 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.activation = Activation()
user.password = 'foo'
user1 = User(username='sontek1', email='[email protected]')
user1.activation = Activation()
user1.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
示例4: test_activate
# 需要导入模块: from horus.views import RegisterController [as 别名]
# 或者: from horus.views.RegisterController import activate [as 别名]
def test_activate(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('foo')
user.activation = Activation()
self.session.add(user)
self.session.flush()
request = testing.DummyRequest()
request.matchdict = Mock()
def get(key, default):
if key == 'code':
return user.activation.code
else:
return user.pk
request.matchdict.get = get
controller = RegisterController(request)
response = controller.activate()
user = User.get_by_user_name(request, 'sontek')
assert user.is_activated
assert response.status_int == 302