From 64058c989ad6ccffac5085d09e6675bcab8976fd Mon Sep 17 00:00:00 2001 From: Nick Smith Date: Fri, 20 Jun 2014 12:15:37 +0100 Subject: [PATCH] Add userprofile creation method tests --- wagtail/wagtailusers/tests.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailusers/tests.py b/wagtail/wagtailusers/tests.py index a360fe468..f9762e5c9 100644 --- a/wagtail/wagtailusers/tests.py +++ b/wagtail/wagtailusers/tests.py @@ -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)