Add userprofile creation method tests

This commit is contained in:
Nick Smith 2014-06-20 12:15:37 +01:00
parent 4ce37c2653
commit 64058c989a

View file

@ -1,6 +1,6 @@
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from wagtail.wagtailusers.models import User, UserProfile
from wagtail.tests.utils import WagtailTestUtils
@ -114,3 +114,19 @@ class TestUserEditView(TestCase, WagtailTestUtils):
# Should not redirect to index
self.assertEqual(response.status_code, 200)
class TestUserProfileCreation(TestCase, WagtailTestUtils):
def setUp(self):
# Create a user
self.test_user = User.objects.create_user(username='testuser', email='testuser@email.com', password='password')
def test_user_created_without_profile(self):
self.assertEqual(UserProfile.objects.filter(user=self.test_user).count(), 0)
with self.assertRaises(UserProfile.DoesNotExist):
self.test_user.userprofile
def test_user_profile_created_when_method_called(self):
self.assertIsInstance(self.test_user.get_profile(), UserProfile)
# and get it from the db too
self.assertEqual(UserProfile.objects.filter(user=self.test_user).count(), 1)