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
eca18a12
Commit
eca18a12
authored
Mar 27, 2013
by
Victor Shnayder
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1752 from MITx/fix/will/bug_294
Fix bug 294
parents
a04881ce
cddc8686
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
4 deletions
+111
-4
common/djangoapps/student/views.py
+4
-4
lms/djangoapps/courseware/tests/test_login.py
+107
-0
No files found.
common/djangoapps/student/views.py
View file @
eca18a12
...
...
@@ -369,14 +369,14 @@ def login_user(request, error=""):
try
:
user
=
User
.
objects
.
get
(
email
=
email
)
except
User
.
DoesNotExist
:
log
.
warning
(
"Login failed - Unknown user email: {0}"
.
format
(
email
))
log
.
warning
(
u
"Login failed - Unknown user email: {0}"
.
format
(
email
))
return
HttpResponse
(
json
.
dumps
({
'success'
:
False
,
'value'
:
'Email or password is incorrect.'
}))
# TODO: User error message
username
=
user
.
username
user
=
authenticate
(
username
=
username
,
password
=
password
)
if
user
is
None
:
log
.
warning
(
"Login failed - password for {0} is invalid"
.
format
(
email
))
log
.
warning
(
u
"Login failed - password for {0} is invalid"
.
format
(
email
))
return
HttpResponse
(
json
.
dumps
({
'success'
:
False
,
'value'
:
'Email or password is incorrect.'
}))
...
...
@@ -392,7 +392,7 @@ def login_user(request, error=""):
log
.
critical
(
"Login failed - Could not create session. Is memcached running?"
)
log
.
exception
(
e
)
log
.
info
(
"Login success - {0} ({1})"
.
format
(
username
,
email
))
log
.
info
(
u
"Login success - {0} ({1})"
.
format
(
username
,
email
))
try_change_enrollment
(
request
)
...
...
@@ -400,7 +400,7 @@ def login_user(request, error=""):
return
HttpResponse
(
json
.
dumps
({
'success'
:
True
}))
log
.
warning
(
"Login failed - Account not active for user {0}, resending activation"
.
format
(
username
))
log
.
warning
(
u
"Login failed - Account not active for user {0}, resending activation"
.
format
(
username
))
reactivation_email_for_user
(
user
)
not_activated_msg
=
"This account has not been activated. We have "
+
\
...
...
lms/djangoapps/courseware/tests/test_login.py
0 → 100644
View file @
eca18a12
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.core.urlresolvers
import
reverse
from
django.contrib.auth.models
import
User
from
student.models
import
Registration
,
UserProfile
import
json
class
LoginTest
(
TestCase
):
'''
Test student.views.login_user() view
'''
def
setUp
(
self
):
# Create one user and save it to the database
self
.
user
=
User
.
objects
.
create_user
(
'test'
,
'test@edx.org'
,
'test_password'
)
self
.
user
.
is_active
=
True
self
.
user
.
save
()
# Create a registration for the user
Registration
()
.
register
(
self
.
user
)
# Create a profile for the user
UserProfile
(
user
=
self
.
user
)
.
save
()
# Create the test client
self
.
client
=
Client
()
# Store the login url
self
.
url
=
reverse
(
'login'
)
def
test_login_success
(
self
):
response
=
self
.
_login_response
(
'test@edx.org'
,
'test_password'
)
self
.
_assert_response
(
response
,
success
=
True
)
def
test_login_success_unicode_email
(
self
):
unicode_email
=
u'test@edx.org'
+
unichr
(
40960
)
self
.
user
.
email
=
unicode_email
self
.
user
.
save
()
response
=
self
.
_login_response
(
unicode_email
,
'test_password'
)
self
.
_assert_response
(
response
,
success
=
True
)
def
test_login_fail_no_user_exists
(
self
):
response
=
self
.
_login_response
(
'not_a_user@edx.org'
,
'test_password'
)
self
.
_assert_response
(
response
,
success
=
False
,
value
=
'Email or password is incorrect'
)
def
test_login_fail_wrong_password
(
self
):
response
=
self
.
_login_response
(
'test@edx.org'
,
'wrong_password'
)
self
.
_assert_response
(
response
,
success
=
False
,
value
=
'Email or password is incorrect'
)
def
test_login_not_activated
(
self
):
# De-activate the user
self
.
user
.
is_active
=
False
self
.
user
.
save
()
# Should now be unable to login
response
=
self
.
_login_response
(
'test@edx.org'
,
'test_password'
)
self
.
_assert_response
(
response
,
success
=
False
,
value
=
"This account has not been activated"
)
def
test_login_unicode_email
(
self
):
unicode_email
=
u'test@edx.org'
+
unichr
(
40960
)
response
=
self
.
_login_response
(
unicode_email
,
'test_password'
)
self
.
_assert_response
(
response
,
success
=
False
)
def
test_login_unicode_password
(
self
):
unicode_password
=
u'test_password'
+
unichr
(
1972
)
response
=
self
.
_login_response
(
'test@edx.org'
,
unicode_password
)
self
.
_assert_response
(
response
,
success
=
False
)
def
_login_response
(
self
,
email
,
password
):
post_params
=
{
'email'
:
email
,
'password'
:
password
}
return
self
.
client
.
post
(
self
.
url
,
post_params
)
def
_assert_response
(
self
,
response
,
success
=
None
,
value
=
None
):
'''
Assert that the response had status 200 and returned a valid
JSON-parseable dict.
If success is provided, assert that the response had that
value for 'success' in the JSON dict.
If value is provided, assert that the response contained that
value for 'value' in the JSON dict.
'''
self
.
assertEqual
(
response
.
status_code
,
200
)
try
:
response_dict
=
json
.
loads
(
response
.
content
)
except
ValueError
:
self
.
fail
(
"Could not parse response content as JSON:
%
s"
%
str
(
response
.
content
))
if
success
is
not
None
:
self
.
assertEqual
(
response_dict
[
'success'
],
success
)
if
value
is
not
None
:
msg
=
(
"'
%
s' did not contain '
%
s'"
%
(
str
(
response_dict
[
'value'
]),
str
(
value
)))
self
.
assertTrue
(
value
in
response_dict
[
'value'
],
msg
)
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