From 342f3d53110daecb87aa1b661efb332594af2160 Mon Sep 17 00:00:00 2001 From: Jason Ward Date: Wed, 26 Sep 2012 17:17:27 -0400 Subject: [PATCH] refs #8: name changes and used kwargs in one of the tests --- authority/permissions.py | 14 +++++++------- authority/tests.py | 15 ++++++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/authority/permissions.py b/authority/permissions.py index 6bf84e6..a31a2e8 100644 --- a/authority/permissions.py +++ b/authority/permissions.py @@ -73,7 +73,7 @@ class BasePermission(object): )] = True return user_permissions, group_permissions - def _authority_prime_perm_caches(self): + def _prime_perm_caches(self): """ Prime both the user and group caches and put them on the ``self.user``. In addition add a cache filled flag on ``self.user``. @@ -84,7 +84,7 @@ class BasePermission(object): self.user._authority_perm_cache_filled = True @property - def perm_cache(self): + def _perm_cache(self): """ cached_permissions will generate the cache in a lazy fashion. """ @@ -102,11 +102,11 @@ class BasePermission(object): return self.user._authority_perm_cache # Prime the cache. - self._authority_prime_perm_caches() + self._prime_perm_caches() return self.user._authority_perm_cache @property - def group_perm_cache(self): + def _group_perm_cache(self): """ cached_permissions will generate the cache in a lazy fashion. """ @@ -122,7 +122,7 @@ class BasePermission(object): return self.user._authority_group_perm_cache # Prime the cache. - self._authority_prime_perm_caches() + self._prime_perm_caches() return self.user._authority_group_perm_cache def invalidate_permissions_cache(self): @@ -164,11 +164,11 @@ class BasePermission(object): )) # Check to see if the permission is in the cache. - has_perm = _user_has_perms(self.perm_cache) + has_perm = _user_has_perms(self._perm_cache) # Optionally check group permissions if check_groups: - has_perm = has_perm or _user_has_perms(self.group_perm_cache) + has_perm = has_perm or _user_has_perms(self._group_perm_cache) return has_perm else: return Permission.objects.user_permissions( diff --git a/authority/tests.py b/authority/tests.py index d9fc36a..79d8d46 100644 --- a/authority/tests.py +++ b/authority/tests.py @@ -218,7 +218,12 @@ class PerformanceTest(SmartCachingTestCase): # Regardless of the number groups permissions, it should only take one # query to check both users and groups. with self.assertNumQueries(1): - self.user_check.has_user_perms('foo', self.user, True, True) + self.user_check.has_user_perms( + 'foo', + self.user, + approved=True, + check_groups=True, + ) def test_invalidate_permissions_cache(self): # Show that calling invalidate_permissions_cache will cause extra @@ -319,8 +324,8 @@ class GroupPermissionCacheTestCase(SmartCachingTestCase): ) self.assertFalse(can_foo_with_group) - self.assertEqual(self.group_check.perm_cache, {}) - self.assertEqual(self.group_check.group_perm_cache, {}) + self.assertEqual(self.group_check._perm_cache, {}) + self.assertEqual(self.group_check._group_perm_cache, {}) # Create a permission with just that group. Permission.objects.create( @@ -341,5 +346,5 @@ class GroupPermissionCacheTestCase(SmartCachingTestCase): ) self.assertTrue(can_foo_with_group) - self.assertEqual(self.group_check.perm_cache, {}) - self.assertEqual(self.group_check.group_perm_cache, {}) + self.assertEqual(self.group_check._perm_cache, {}) + self.assertEqual(self.group_check._group_perm_cache, {})