From the course: Securing Django Applications

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Unit test for access control and group permissions

Unit test for access control and group permissions - Django Tutorial

From the course: Securing Django Applications

Start my 1-month free trial

Unit test for access control and group permissions

- [Instructor] Let's write another access control test to ensure group permissions are working properly. Before we get started, Let's take a look at this sign permission, shortcut function we used. As you can see the function imports the group model and then imports the assigned permission function from django guardian. And then for every group and the permissions, we are getting the group model instance. And then assigning each permission using the django guardian shortcut. Next, we have a function that checks whether a given group has permission to access a given object. We fetch the group model instance. And then we use the get objects for group django guardian shortcut to check whether out of the set of all objects that this group has permission to whether the given object is in that set. And lastly, we have the user has group perm function. Which will check whether a user has permission to access through their group…

Contents