Пример #1
0
    def test_get_all_permissions_mixed_user_and_group(self):
        permissions = Permission.objects.filter(content_type__app_label='auth',
                                                codename__in=[
                                                    'add_user', 'change_user',
                                                    'add_group', 'change_group'
                                                ])
        user = User.objects.create_user(username='******',
                                        password='******')
        group = Group.objects.create(name='group')
        group.user_set.add(user)

        user.user_permissions.add(*permissions.filter(
            content_type__model='user'))
        group.permissions.add(*permissions.filter(content_type__model='group'))

        backend = ChemoPermissionsBackend()

        self.assertEqual(
            set(
                permissions.filter(content_type__model='group').values_list(
                    'codename', flat=True)),
            set(backend.get_all_permissions(user, group)))
        self.assertEqual(
            set(
                permissions.filter(content_type__model='user').values_list(
                    'codename', flat=True)),
            set(backend.get_all_permissions(user, user)))
Пример #2
0
    def test_get_all_permissions_anonymous_user(self):
        class FooBar:
            pass

        obj = FooBar()
        user = AnonymousUser()
        backend = ChemoPermissionsBackend()
        self.assertEqual(set(), backend.get_all_permissions(user, obj))
Пример #3
0
    def test_get_all_permissions_non_model_instance(self):
        class FooBar:
            pass

        obj = FooBar()
        user = User.objects.create_user(username='******',
                                        password='******')
        backend = ChemoPermissionsBackend()
        self.assertEqual(set(), backend.get_all_permissions(user, obj))