diff --git a/openwisp_utils/tests.py b/openwisp_utils/tests.py index 41826295..ff3a2d3b 100644 --- a/openwisp_utils/tests.py +++ b/openwisp_utils/tests.py @@ -5,6 +5,7 @@ from unittest import TextTestResult, mock from django.conf import settings +from django.contrib.auth.models import Permission from django.db import DEFAULT_DB_ALIAS, connections from django.test.runner import DiscoverRunner from django.test.utils import CaptureQueriesContext @@ -170,3 +171,86 @@ def assertNumQueries(self, num, func=None, *args, using=DEFAULT_DB_ALIAS, **kwar with context: func(*args, **kwargs) + + +class AdminActionPermTestMixin: + def _test_action_permission( + self, + path, + action, + user, + obj, + message, + message_level='success', + required_perms=None, + extra_payload=None, + ): + all_perms = {'add', 'change', 'delete', 'view'} + required_perms = required_perms or all_perms + extra_payload = extra_payload or {} + self.client.force_login(user) + payload = { + '_selected_action': [obj.pk], + 'action': action, + 'post': 'yes', + **extra_payload, + } + admin_action_option = f'