Commit 222882d8 authored by Vitalis Salis's avatar Vitalis Salis

astakos: Rename email templates and parameters

In order to add functionality for sending an email
to the old user email, some template names and
parameters were changed for clarity.
parent acad05e7
......@@ -90,14 +90,14 @@ class TestUserUtils(TestCase):
self.assertEqual(len(mail.outbox), 4)
verify_sent_email(email_dict, mail.outbox[3])
@patch('astakos.im.user_utils.send_change_email')
def test_change_user_email(self, send_change_email_mock):
@patch('astakos.im.user_utils.send_change_email_to_new')
def test_change_user_email(self, send_change_email_to_new_mock):
"""
The `change_user_email` method should check if the email
provided is valid. If it is invalid it should raise a
`ValidationError` exception. Otherwise it should create
an `EmailChange` instance on the database and call
`send_change_email` with the email template provided.
`send_change_email_to_new` with the email template provided.
"""
user = get_local_user('something@something.com')
......@@ -107,23 +107,23 @@ class TestUserUtils(TestCase):
with self.assertRaises(ValidationError):
change_user_email(user, new_email)
# valid `new_email`, default `email_template_name`
# valid `new_email`, default `email_to_new_template_name`
new_email = 'something@somethingelse.com'
default_template = 'registration/email_change_email.txt'
default_to_new_template = 'registration/email_change_email_new_email.txt'
change_user_email(user, new_email)
email_change = EmailChange.objects.get(new_email_address=new_email)
send_change_email_mock.assert_called_once_with(email_change, default_template)
send_change_email_to_new_mock.assert_called_once_with(email_change, default_to_new_template)
self.assertTrue(user.email_change_is_pending())
self.assertEqual(user.emailchanges.count(), 1)
# valid mail, different `email_template_name`
template = 'mytemplate/template.txt'
change_user_email(user, new_email, email_template_name=template)
# valid mail, different `email_to_new_template_name`
to_new_template = 'mytemplate/template.txt'
change_user_email(user, new_email, email_to_new_template_name=to_new_template)
email_change = EmailChange.objects.get(new_email_address=new_email)
send_change_email_mock.assert_called_with(email_change, template)
send_change_email_to_new_mock.assert_called_with(email_change, to_new_template)
# the previous email change was deleted
self.assertEqual(user.emailchanges.count(), 1)
......
......@@ -206,7 +206,7 @@ def send_feedback(msg, data, user, email_template_name='im/feedback_mail.txt'):
def change_user_email(user, new_email,
email_template_name='registration/email_change_email.txt'):
email_to_new_template_name='registration/email_change_email_new_email.txt'):
validate_email(new_email)
......@@ -224,13 +224,13 @@ def change_user_email(user, new_email,
activation_key=activation_key
)
send_change_email(email_change, email_template_name)
send_change_email_to_new(email_change, email_to_new_template_name)
return email_change
def send_change_email(ec, email_template_name=(
'registration/email_change_email.txt')):
def send_change_email_to_new(ec, email_template_name=(
'registration/email_change_email_new_email.txt')):
url = ec.get_url()
url = urlparse.urljoin(settings.BASE_URL, url)
c = {'url': url,
......
......@@ -46,7 +46,7 @@ from astakos.im.forms import LoginForm, InvitationForm, FeedbackForm, \
from astakos.im.forms import ExtendedProfileForm as ProfileForm
from synnefo.lib.services import get_public_endpoint
from astakos.im.user_utils import send_feedback, logout as auth_logout, \
invite as invite_func, send_change_email, change_user_email
invite as invite_func, change_user_email
from astakos.im import settings
from astakos.im import presentation
from astakos.im import auth_providers as auth
......@@ -733,7 +733,7 @@ def approval_terms(request, term_id=None,
@cookie_fix
@transaction.commit_on_success
def request_change_email(request,
email_template_name='registration/email_change_email.txt',
email_to_new_template_name='registration/email_change_email_new_email.txt',
form_template_name='registration/email_change_form.html',
extra_context=None):
......@@ -761,7 +761,7 @@ def request_change_email(request,
change_user_email(
user=request.user,
new_email=new_email,
email_template_name=email_template_name
email_to_new_template_name=email_to_new_template_name,
)
msg = _(astakos_messages.EMAIL_CHANGE_REGISTERED)
messages.success(request, msg)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment