Commit b3f50537 by David Baumgold

Merge pull request #2521 from edx/db/create-account-400

unit tests to handle duplicate user registration attempts
parents 8a954745 a143309a
...@@ -3,11 +3,13 @@ This test file will test registration, login, activation, and session activity t ...@@ -3,11 +3,13 @@ This test file will test registration, login, activation, and session activity t
""" """
import time import time
import mock import mock
import unittest
from django.test.utils import override_settings from django.test.utils import override_settings
from django.core.cache import cache from django.core.cache import cache
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.conf import settings from django.conf import settings
from django.contrib.auth.models import User
from contentstore.tests.utils import parse_json, user, registration, AjaxEnabledTestClient from contentstore.tests.utils import parse_json, user, registration, AjaxEnabledTestClient
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
...@@ -19,6 +21,7 @@ from pytz import UTC ...@@ -19,6 +21,7 @@ from pytz import UTC
from freezegun import freeze_time from freezegun import freeze_time
@override_settings(MODULESTORE=TEST_MODULESTORE) @override_settings(MODULESTORE=TEST_MODULESTORE)
class ContentStoreTestCase(ModuleStoreTestCase): class ContentStoreTestCase(ModuleStoreTestCase):
def _login(self, email, password): def _login(self, email, password):
...@@ -119,6 +122,32 @@ class AuthTestCase(ContentStoreTestCase): ...@@ -119,6 +122,32 @@ class AuthTestCase(ContentStoreTestCase):
self.create_account(self.username, self.email, self.pw) self.create_account(self.username, self.email, self.pw)
self.activate_user(self.email) 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): def test_login(self):
self.create_account(self.username, self.email, self.pw) self.create_account(self.username, self.email, self.pw)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment