Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
84463ef1
Commit
84463ef1
authored
Sep 25, 2014
by
Will Daly
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test for email activation and confirmation
parent
afa39a86
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
lms/djangoapps/student_account/test/test_views.py
+41
-1
lms/templates/student_account/emails/email_change_confirmation/message_body.txt
+1
-1
No files found.
lms/djangoapps/student_account/test/test_views.py
View file @
84463ef1
# -*- coding: utf-8 -*-
""" Tests for student account views. """
import
re
from
urllib
import
urlencode
from
mock
import
patch
import
ddt
from
django.test
import
TestCase
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
django.core
import
mail
from
util.testing
import
UrlResetMixin
from
user_api.api
import
account
as
account_api
...
...
@@ -76,7 +78,7 @@ class StudentAccountViewTest(UrlResetMixin, TestCase):
response
=
self
.
client
.
get
(
reverse
(
'account_index'
))
self
.
assertContains
(
response
,
"Student Account"
)
def
test_
email_change_request_handler
(
self
):
def
test_
change_email
(
self
):
response
=
self
.
_change_email
(
self
.
NEW_EMAIL
,
self
.
PASSWORD
)
self
.
assertEquals
(
response
.
status_code
,
204
)
...
...
@@ -84,6 +86,38 @@ class StudentAccountViewTest(UrlResetMixin, TestCase):
profile_info
=
profile_api
.
profile_info
(
self
.
USERNAME
)
self
.
assertEquals
(
profile_info
[
'email'
],
self
.
OLD_EMAIL
)
# Check that an email was sent with the activation key
self
.
assertEqual
(
len
(
mail
.
outbox
),
1
)
self
.
_assert_email
(
mail
.
outbox
[
0
],
[
self
.
NEW_EMAIL
],
u'Email Change Request'
,
u'There was recently a request to change the email address'
)
# Retrieve the activation key from the email
email_body
=
mail
.
outbox
[
0
]
.
body
result
=
re
.
search
(
'/email_change_confirm/([^
\n
]+)'
,
email_body
)
self
.
assertIsNot
(
result
,
None
)
activation_key
=
result
.
group
(
1
)
# Attempt to activate the email
response
=
self
.
client
.
get
(
reverse
(
'email_change_confirm'
,
kwargs
=
{
'key'
:
activation_key
}))
self
.
assertEqual
(
response
.
status_code
,
200
)
# Verify that the email was changed
profile_info
=
profile_api
.
profile_info
(
self
.
USERNAME
)
self
.
assertEquals
(
profile_info
[
'email'
],
self
.
NEW_EMAIL
)
# Verify that notification emails were sent
self
.
assertEqual
(
len
(
mail
.
outbox
),
2
)
self
.
_assert_email
(
mail
.
outbox
[
1
],
[
self
.
OLD_EMAIL
,
self
.
NEW_EMAIL
],
u'Email Change Successful'
,
u'You successfully changed the email address'
)
def
test_email_change_wrong_password
(
self
):
response
=
self
.
_change_email
(
self
.
NEW_EMAIL
,
"wrong password"
)
self
.
assertEqual
(
response
.
status_code
,
401
)
...
...
@@ -202,3 +236,9 @@ class StudentAccountViewTest(UrlResetMixin, TestCase):
for
method
in
wrong_methods
:
response
=
getattr
(
self
.
client
,
method
)(
url
)
self
.
assertEqual
(
response
.
status_code
,
405
)
def
_assert_email
(
self
,
email
,
expected_to
,
expected_subject
,
expected_body
):
"""Check whether an email has the correct properties. """
self
.
assertEqual
(
email
.
to
,
expected_to
)
self
.
assertIn
(
expected_subject
,
email
.
subject
)
self
.
assertIn
(
expected_body
,
email
.
body
)
lms/templates/student_account/emails/email_change_confirmation/message_body.txt
View file @
84463ef1
...
...
@@ -6,7 +6,7 @@
${_("Hi there,")}
## Preamble
${_("You successfully changed the email address associated with your"
${_("You successfully changed the email address associated with your
"
"{platform_name} account from {old_email} to {new_email}.").format(
platform_name=settings.PLATFORM_NAME,
old_email=old_email,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment