Commit 7e35bf19 by Will Daly

Merge pull request #1846 from MITx/feature/zoldak/test-user-profile-factory

Convert login tests to use factories
parents dce0b53c bb1134b8
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,7 +43,6 @@ 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,
......@@ -54,7 +54,6 @@ class LoginTest(TestCase):
value='Email or password is incorrect')
def test_login_not_activated(self):
# De-activate the user
self.user.is_active = False
self.user.save()
......@@ -64,7 +63,6 @@ class LoginTest(TestCase):
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')
......
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