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 query all the permissions but having a tough time figuring out how can I write the test script for it. Here's the script:-
def test_group_permission(self):
for group in Group.objects.all():
permissions = group.permissions.all()
print(permissions)
With the above code, this is the output I get:-
<QuerySet [
<Permission: blog | post | Can add post>,
<Permission: blog | post | Can change post>,
<Permission: blog | post | Can delete post>,
<Permission: blog | post | Can view post>
]>
Now, how can I write a proper test(s) script for checking to see if the required permissions are present in a group for that particular model, if it does it returns True else False