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
7e35bf19
Commit
7e35bf19
authored
Apr 11, 2013
by
Will Daly
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1846 from MITx/feature/zoldak/test-user-profile-factory
Convert login tests to use factories
parents
dce0b53c
bb1134b8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
19 deletions
+17
-19
lms/djangoapps/courseware/tests/test_login.py
+17
-19
No files found.
lms/djangoapps/courseware/tests/test_login.py
View file @
7e35bf19
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
from
factories
import
UserFactory
,
RegistrationFactory
,
UserProfileFactory
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
=
User
Factory
.
build
(
username
=
'test'
,
email
=
'test@edx.org
'
)
self
.
user
.
set_password
(
'test_password'
)
self
.
user
.
save
()
# Create a registration for the user
Registration
()
.
register
(
self
.
user
)
registration
=
RegistrationFactory
(
user
=
self
.
user
)
registration
.
register
(
self
.
user
)
registration
.
activate
()
# Create a profile for the user
UserProfile
(
user
=
self
.
user
)
.
save
(
)
UserProfile
Factory
(
user
=
self
.
user
)
# Create the test client
self
.
client
=
Client
()
...
...
@@ -42,19 +43,17 @@ class LoginTest(TestCase):
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'
)
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'
)
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
()
...
...
@@ -62,8 +61,7 @@ class LoginTest(TestCase):
# 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"
)
value
=
"This account has not been activated"
)
def
test_login_unicode_email
(
self
):
unicode_email
=
u'test@edx.org'
+
unichr
(
40960
)
...
...
@@ -95,13 +93,13 @@ class LoginTest(TestCase):
try
:
response_dict
=
json
.
loads
(
response
.
content
)
except
ValueError
:
self
.
fail
(
"Could not parse response content as JSON:
%
s"
%
str
(
response
.
content
))
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
)))
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