|
|
|
''' Tests for ordr.events '''
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
from pyramid.testing import DummyRequest
|
|
|
|
from pyramid_mailer import get_mailer
|
|
|
|
|
|
|
|
from . import app_config, get_example_user # noqa: F401
|
|
|
|
|
|
|
|
|
|
|
|
def test_user_notification_init(app_config): # noqa: F811
|
|
|
|
''' test creation of user notification events '''
|
|
|
|
from ordr.events import UserNotification
|
|
|
|
from ordr.models.account import Role
|
|
|
|
|
|
|
|
user = get_example_user(Role.USER)
|
|
|
|
notification = UserNotification('request', user, 'data')
|
|
|
|
|
|
|
|
assert notification.request == 'request'
|
|
|
|
assert notification.account == user
|
|
|
|
assert notification.data == 'data'
|
|
|
|
assert notification.send_to == user.email
|
|
|
|
|
|
|
|
|
|
|
|
def test_user_notification_init_send_to_override(app_config): # noqa: F811
|
|
|
|
''' test creation of user notification events '''
|
|
|
|
from ordr.events import UserNotification
|
|
|
|
from ordr.models.account import Role
|
|
|
|
|
|
|
|
user = get_example_user(Role.USER)
|
|
|
|
notification = UserNotification('request', user, 'data', 'amy@example.com')
|
|
|
|
|
|
|
|
assert notification.request == 'request'
|
|
|
|
assert notification.account == user
|
|
|
|
assert notification.data == 'data'
|
|
|
|
assert notification.send_to == 'amy@example.com'
|
|
|
|
|
|
|
|
|
|
|
|
def test_notify_user(app_config): # noqa: F811
|
|
|
|
''' test the user notification '''
|
|
|
|
from ordr.events import RegistrationNotification, notify_user
|
|
|
|
from ordr.models.account import Token, Role
|
|
|
|
|
|
|
|
request = DummyRequest()
|
|
|
|
user = get_example_user(Role.USER)
|
|
|
|
token = Token(expires=datetime.utcnow(), hash='some_hash')
|
|
|
|
notification = RegistrationNotification(request, user, {'token': token})
|
|
|
|
notify_user(notification)
|
|
|
|
mailer = get_mailer(request.registry)
|
|
|
|
last_mail = mailer.outbox[-1]
|
|
|
|
|
|
|
|
assert 'Please verify your email address ' in last_mail.html
|
|
|
|
assert 'http://example.com//some_hash' in last_mail.html
|