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
b3f50537
Commit
b3f50537
authored
Feb 10, 2014
by
David Baumgold
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2521 from edx/db/create-account-400
unit tests to handle duplicate user registration attempts
parents
8a954745
a143309a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
cms/djangoapps/contentstore/tests/tests.py
+29
-0
No files found.
cms/djangoapps/contentstore/tests/tests.py
View file @
b3f50537
...
...
@@ -3,11 +3,13 @@ This test file will test registration, login, activation, and session activity t
"""
import
time
import
mock
import
unittest
from
django.test.utils
import
override_settings
from
django.core.cache
import
cache
from
django.core.urlresolvers
import
reverse
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
contentstore.tests.utils
import
parse_json
,
user
,
registration
,
AjaxEnabledTestClient
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
...
...
@@ -19,6 +21,7 @@ from pytz import UTC
from
freezegun
import
freeze_time
@override_settings
(
MODULESTORE
=
TEST_MODULESTORE
)
class
ContentStoreTestCase
(
ModuleStoreTestCase
):
def
_login
(
self
,
email
,
password
):
...
...
@@ -119,6 +122,32 @@ class AuthTestCase(ContentStoreTestCase):
self
.
create_account
(
self
.
username
,
self
.
email
,
self
.
pw
)
self
.
activate_user
(
self
.
email
)
def
test_create_account_username_already_exists
(
self
):
User
.
objects
.
create_user
(
self
.
username
,
self
.
email
,
self
.
pw
)
resp
=
self
.
_create_account
(
self
.
username
,
"abc@def.com"
,
"password"
)
# we have a constraint on unique usernames, so this should fail
self
.
assertEqual
(
resp
.
status_code
,
400
)
def
test_create_account_pw_already_exists
(
self
):
User
.
objects
.
create_user
(
self
.
username
,
self
.
email
,
self
.
pw
)
resp
=
self
.
_create_account
(
"abcdef"
,
"abc@def.com"
,
self
.
pw
)
# we can have two users with the same password, so this should succeed
self
.
assertEqual
(
resp
.
status_code
,
200
)
@unittest.skipUnless
(
settings
.
SOUTH_TESTS_MIGRATE
,
"South migrations required"
)
def
test_create_account_email_already_exists
(
self
):
User
.
objects
.
create_user
(
self
.
username
,
self
.
email
,
self
.
pw
)
resp
=
self
.
_create_account
(
"abcdef"
,
self
.
email
,
"password"
)
# This is tricky. Django's user model doesn't have a constraint on
# unique email addresses, but we *add* that constraint during the
# migration process:
# see common/djangoapps/student/migrations/0004_add_email_index.py
#
# The behavior we *want* is for this account creation request
# to fail, due to this uniqueness constraint, but the request will
# succeed if the migrations have not run.
self
.
assertEqual
(
resp
.
status_code
,
400
)
def
test_login
(
self
):
self
.
create_account
(
self
.
username
,
self
.
email
,
self
.
pw
)
...
...
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