|
@@ -1,6 +1,6 @@
|
|
|
from django.conf import settings
|
|
|
from django.test import TestCase
|
|
|
-from django.contrib.auth.models import User, SiteProfileNotAvailable
|
|
|
+from django.contrib.auth.models import Group, User, SiteProfileNotAvailable
|
|
|
|
|
|
class ProfileTestCase(TestCase):
|
|
|
fixtures = ['authtestdata.json']
|
|
@@ -26,10 +26,41 @@ class ProfileTestCase(TestCase):
|
|
|
user = User.objects.get(username='testclient')
|
|
|
self.assertRaises(SiteProfileNotAvailable, user.get_profile)
|
|
|
|
|
|
- # Bad syntax in AUTH_PROFILE_MODULE:
|
|
|
+ # Bad syntax in AUTH_PROFILE_MODULE:
|
|
|
settings.AUTH_PROFILE_MODULE = 'foobar'
|
|
|
self.assertRaises(SiteProfileNotAvailable, user.get_profile)
|
|
|
|
|
|
# module that doesn't exist
|
|
|
settings.AUTH_PROFILE_MODULE = 'foo.bar'
|
|
|
self.assertRaises(SiteProfileNotAvailable, user.get_profile)
|
|
|
+
|
|
|
+
|
|
|
+class NaturalKeysTestCase(TestCase):
|
|
|
+ fixtures = ['authtestdata.json']
|
|
|
+
|
|
|
+ def test_user_natural_key(self):
|
|
|
+ staff_user = User.objects.get(username='staff')
|
|
|
+ self.assertEquals(User.objects.get_by_natural_key('staff'), staff_user)
|
|
|
+ self.assertEquals(staff_user.natural_key(), ('staff',))
|
|
|
+
|
|
|
+ def test_group_natural_key(self):
|
|
|
+ users_group = Group.objects.create(name='users')
|
|
|
+ self.assertEquals(Group.objects.get_by_natural_key('users'), users_group)
|
|
|
+
|
|
|
+
|
|
|
+class LoadDataWithoutNaturalKeysTestCase(TestCase):
|
|
|
+ fixtures = ['regular.json']
|
|
|
+
|
|
|
+ def test_user_is_created_and_added_to_group(self):
|
|
|
+ user = User.objects.get(username='my_username')
|
|
|
+ group = Group.objects.get(name='my_group')
|
|
|
+ self.assertEquals(group, user.groups.get())
|
|
|
+
|
|
|
+
|
|
|
+class LoadDataWithNaturalKeysTestCase(TestCase):
|
|
|
+ fixtures = ['natural.json']
|
|
|
+ def test_user_is_created_and_added_to_group(self):
|
|
|
+ user = User.objects.get(username='my_username')
|
|
|
+ group = Group.objects.get(name='my_group')
|
|
|
+ self.assertEquals(group, user.groups.get())
|
|
|
+
|