Skip to content Skip to sidebar Skip to footer

Tests For Checking The Permissions Of A Group

I am trying to write tests for an app to check that a group has the required permission for a particular model or not in django. App Name:- Blog Model Name:- Post I am able to que

Solution 1:

The Django documentation is terrible for explaining the relationship between user and group permissions. I think the confusion is from the fact that Group is some kind of appendage for User and Django assumes, incorrectly, that people will usually be checking permissions on the User object.

Try this if you want strings in the same way User.objects.get(name = ...).get_group_permissions() gives permissions as strings:

deftest_group_permission(self):
            for group in Group.objects.all():
                permissions = group.permissions.all()
                print([i.content_type.app_label + '.' + i.codename for i in group.permissions.all()])

Post a Comment for "Tests For Checking The Permissions Of A Group"