Commit c37dc913 by Will Daly

Copy changes to the activation email

parent d2786a64
...@@ -8,6 +8,8 @@ from student.views import ( ...@@ -8,6 +8,8 @@ from student.views import (
reactivation_email_for_user, change_email_request, do_email_change_request, confirm_email_change reactivation_email_for_user, change_email_request, do_email_change_request, confirm_email_change
) )
from student.models import UserProfile, PendingEmailChange from student.models import UserProfile, PendingEmailChange
from django.core.urlresolvers import reverse
from django.core import mail
from django.contrib.auth.models import User, AnonymousUser from django.contrib.auth.models import User, AnonymousUser
from django.test import TestCase, TransactionTestCase from django.test import TestCase, TransactionTestCase
from django.test.client import RequestFactory from django.test.client import RequestFactory
...@@ -62,6 +64,73 @@ class EmailTestMixin(object): ...@@ -62,6 +64,73 @@ class EmailTestMixin(object):
self.addCleanup(settings.ALLOWED_HOSTS.pop) self.addCleanup(settings.ALLOWED_HOSTS.pop)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
class ActivationEmailTests(TestCase):
"""Test sending of the activation email. """
ACTIVATION_SUBJECT = "Activate Your edX Account"
# Text fragments we expect in the body of an email
# sent from an OpenEdX installation.
OPENEDX_FRAGMENTS = [
"Thank you for signing up for {platform}.".format(platform=settings.PLATFORM_NAME),
"http://edx.org/activate/",
(
"if you require assistance, check the help section of the "
"{platform} website".format(platform=settings.PLATFORM_NAME)
)
]
# Text fragments we expect in the body of an email
# sent from an EdX-controlled domain.
EDX_DOMAIN_FRAGMENTS = [
"Thank you for signing up for {platform}".format(platform=settings.PLATFORM_NAME),
"http://edx.org/activate/",
"https://www.edx.org/contact-us",
"This email was automatically sent by edx.org"
]
def setUp(self):
super(ActivationEmailTests, self).setUp()
def test_activation_email(self):
self._create_account()
self._assert_activation_email(self.ACTIVATION_SUBJECT, self.OPENEDX_FRAGMENTS)
@patch.dict(settings.FEATURES, {'IS_EDX_DOMAIN': True})
def test_activation_email_edx_domain(self):
self._create_account()
self._assert_activation_email(self.ACTIVATION_SUBJECT, self.EDX_DOMAIN_FRAGMENTS)
def _create_account(self):
"""Create an account, triggering the activation email. """
url = reverse('create_account')
params = {
'username': 'test_user',
'email': 'test_user@example.com',
'password': 'edx',
'name': 'Test User',
'honor_code': True,
'terms_of_service': True
}
resp = self.client.post(url, params)
self.assertEqual(
resp.status_code, 200,
msg=u"Could not create account (status {status}). The response was {response}".format(
status=resp.status_code,
response=resp.content
)
)
def _assert_activation_email(self, subject, body_fragments):
"""Verify that the activation email was sent. """
self.assertEqual(len(mail.outbox), 1)
msg = mail.outbox[0]
self.assertEqual(msg.subject, subject)
for fragment in body_fragments:
self.assertIn(fragment, msg.body)
@patch('student.views.render_to_string', Mock(side_effect=mock_render_to_string, autospec=True)) @patch('student.views.render_to_string', Mock(side_effect=mock_render_to_string, autospec=True))
@patch('django.contrib.auth.models.User.email_user') @patch('django.contrib.auth.models.User.email_user')
class ReactivationEmailTests(EmailTestMixin, TestCase): class ReactivationEmailTests(EmailTestMixin, TestCase):
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
<%! from django.utils.translation import ugettext as _ %> <%! from django.utils.translation import ugettext as _ %>
${_("Thank you for signing up for {platform_name}.").format(platform_name=settings.PLATFORM_NAME)} ${_("Thank you for signing up for {platform_name}.").format(platform_name=settings.PLATFORM_NAME)}
${_("To get started, please activate your account by clicking on the link below" ${_("Change your life and start learning today by activating your "
" (you may also copy and paste the link into your browser's address" "{platform_name} account. Click on the link below or copy and "
" bar).").format(platform_name=settings.PLATFORM_NAME)} "paste it into your browser's address bar.").format(
platform_name=settings.PLATFORM_NAME
)}
% if is_secure: % if is_secure:
https://${ site }/activate/${ key } https://${ site }/activate/${ key }
...@@ -12,14 +14,16 @@ ${_("To get started, please activate your account by clicking on the link below" ...@@ -12,14 +14,16 @@ ${_("To get started, please activate your account by clicking on the link below"
http://${ site }/activate/${ key } http://${ site }/activate/${ key }
% endif % endif
% if settings.PLATFORM_NAME == "edX": % if settings.FEATURES.get('IS_EDX_DOMAIN'):
${_("Activation ensures that you can register for {platform_name} courses and" ${_("After you activate your account, you can sign up for "
" access the courseware." "and take any of the hundreds of courses {platform_name} offers."
" If you require assistance, please use our web form at" ).format(platform_name=settings.PLATFORM_NAME)}
" {contact_us} or email {info_address}.").format(
platform_name=settings.PLATFORM_NAME, ${_("If you need help, please use our web form at "
contact_us='https://www.edx.org/contact-us', "{contact_us_url} or email {info_email_address}."
info_address=settings.CONTACT_EMAIL ).format(
contact_us_url="https://www.edx.org/contact-us",
info_email_address=settings.CONTACT_EMAIL
)} )}
${_("We hope you enjoy learning with {platform_name}!").format( ${_("We hope you enjoy learning with {platform_name}!").format(
...@@ -29,12 +33,11 @@ ${_("We hope you enjoy learning with {platform_name}!").format( ...@@ -29,12 +33,11 @@ ${_("We hope you enjoy learning with {platform_name}!").format(
${_("The {platform_name} Team").format(platform_name=settings.PLATFORM_NAME)} ${_("The {platform_name} Team").format(platform_name=settings.PLATFORM_NAME)}
${_("This email was automatically sent by {site_name} because someone " ${_("This email was automatically sent by {site_name} because someone "
"attempted to create an {platform_name} account using this email address. If you " "attempted to create an {platform_name} account using this email address."
"did not attempt to create this account and do not activate the account, " ).format(
"you will no longer receive emails from {platform_name}.").format( site_name=settings.SITE_NAME,
platform_name=settings.PLATFORM_NAME, platform_name=settings.PLATFORM_NAME
site_name=settings.SITE_NAME )}
)}
% elif stanford_theme_enabled(): ## Temporary hack until we develop a better way to adjust language % elif stanford_theme_enabled(): ## Temporary hack until we develop a better way to adjust language
${_("If you didn't request this, you don't need to do anything; you won't " ${_("If you didn't request this, you don't need to do anything; you won't "
......
...@@ -1306,7 +1306,10 @@ class RegistrationViewTest(ApiTestCase): ...@@ -1306,7 +1306,10 @@ class RegistrationViewTest(ApiTestCase):
sent_email = mail.outbox[0] sent_email = mail.outbox[0]
self.assertEqual(sent_email.to, [self.EMAIL]) self.assertEqual(sent_email.to, [self.EMAIL])
self.assertEqual(sent_email.subject, "Activate Your edX Account") self.assertEqual(sent_email.subject, "Activate Your edX Account")
self.assertIn("activate your account", sent_email.body) self.assertIn(
u"activating your {platform} account".format(platform=settings.PLATFORM_NAME),
sent_email.body
)
@ddt.data( @ddt.data(
{"email": ""}, {"email": ""},
......
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