def test_get_multi_crud_query(self):
        admin = User.objects.get(name='admin user')
        zoo = Zoo.objects.first()

        # Everything defaults to isnull
        query = get_multi_crud_query()
        self.assertEqual(0, Permission.objects.filter(query).count())

        # It gets the one entry with null agent
        query = get_multi_crud_query(role='zoo.visitor', target=ANY)
        self.assertEqual(1, Permission.objects.filter(query).count())

        # It filters agents and targets properly
        query = get_multi_crud_query(role=ANY, agent=admin, target=zoo)
        self.assertEqual(1, Permission.objects.filter(query).count())
Ejemplo n.º 2
0
def get_perms(*args, **kwargs):
    """
    Gets all Permissions matching the query.
    Accepts role, agent, and target kwargs.
    """
    return Permission.objects.filter(get_multi_crud_query(*args, **kwargs))