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
207e500a
Commit
207e500a
authored
Mar 13, 2015
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't allow empty string or None for email.
parent
28ad1388
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
5 deletions
+18
-5
openedx/core/djangoapps/user_api/accounts/api.py
+4
-3
openedx/core/djangoapps/user_api/accounts/tests/test_views.py
+14
-2
No files found.
openedx/core/djangoapps/user_api/accounts/api.py
View file @
207e500a
...
...
@@ -114,8 +114,9 @@ def update_account_settings(requesting_user, update, username=None):
# If user has requested to change email, we must call the multi-step process to handle this.
# It is not handled by the serializer (which considers email to be read-only).
new_email
=
Non
e
changing_email
=
Fals
e
if
"email"
in
update
:
changing_email
=
True
new_email
=
update
[
"email"
]
del
update
[
"email"
]
...
...
@@ -148,7 +149,7 @@ def update_account_settings(requesting_user, update, username=None):
field_errors
=
_add_serializer_errors
(
update
,
serializer
,
field_errors
)
# If the user asked to change email, validate it.
if
new
_email
:
if
changing
_email
:
try
:
validate_new_email
(
existing_user
,
new_email
)
except
ValueError
as
err
:
...
...
@@ -186,7 +187,7 @@ def update_account_settings(requesting_user, update, username=None):
)
# And try to send the email change request if necessary.
if
new
_email
:
if
changing
_email
:
try
:
do_email_change_request
(
existing_user
,
new_email
)
except
ValueError
as
err
:
...
...
openedx/core/djangoapps/user_api/accounts/tests/test_views.py
View file @
207e500a
...
...
@@ -438,8 +438,20 @@ class TestAccountAPI(UserAPITestCase):
get_response
=
self
.
send_get
(
client
)
self
.
assertEqual
(
new_email
,
get_response
.
data
[
"email"
])
# Finally, try changing to an invalid email just to make sure error messages are appropriately returned.
error_response
=
self
.
send_patch
(
client
,
{
"email"
:
"not_an_email"
},
expected_status
=
400
)
@ddt.data
(
(
"not_an_email"
,),
(
""
,),
(
None
,),
)
@ddt.unpack
def
test_patch_invalid_email
(
self
,
bad_email
):
"""
Test a few error cases for email validation (full test coverage lives with do_email_change_request).
"""
client
=
self
.
login_client
(
"client"
,
"user"
)
# Try changing to an invalid email to make sure error messages are appropriately returned.
error_response
=
self
.
send_patch
(
client
,
{
"email"
:
bad_email
},
expected_status
=
400
)
field_errors
=
error_response
.
data
[
"field_errors"
]
self
.
assertEqual
(
"Error thrown from validate_new_email: 'Valid e-mail address required.'"
,
...
...
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