コード例 #1
0
 def test_user_is_checked_for_global_db_permission(self):
     user = User(is_active=True)
     user.save()
     content_type = ContentType(app_label='test_app')
     content_type.save()
     permission = Permission(content_type=content_type,
                             codename='test_permission')
     permission.save()
     user.user_permissions.add(permission)
     backend = PermissionBackend()
     self.assertTrue(backend.has_perm(user, 'test_app.test_permission'))
コード例 #2
0
 def test_inactive_user_has_no_permissions(self):
     user = User(is_active=False, is_staff=True)
     user.save()
     backend = PermissionBackend()
     self.assertFalse(backend.has_perm(user, 'test_app.test_permission'))
コード例 #3
0
 def test_returns_false_if_rule_does_not_exist(self):
     user = User(is_active=True, is_staff=True)
     user.save()
     backend = PermissionBackend()
     self.assertFalse(backend.has_perm(user, 'test_app.absent_permission'))
コード例 #4
0
 def test_user_is_checked_for_object_rule_permission(self):
     user = User(is_active=True, is_staff=False)
     user.save()
     backend = PermissionBackend()
     self.assertTrue(backend.has_perm(user, 'test_app.test_permission', ModelStub()))
コード例 #5
0
 def test_user_is_checked_for_global_rule_permission(self):
     user = User(is_active=True, is_staff=True)
     user.save()
     backend = PermissionBackend()
     self.assertTrue(backend.has_perm(user, 'test_app.test_permission'))