diff --git a/lms/djangoapps/courseware/tests/test_login.py b/lms/djangoapps/courseware/tests/test_login.py index dda58a4462..39259a7137 100644 --- a/lms/djangoapps/courseware/tests/test_login.py +++ b/lms/djangoapps/courseware/tests/test_login.py @@ -1,27 +1,28 @@ 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 = UserFactory.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() + UserProfileFactory(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)