| |
---|
| | from mock import patch |
---|
| | |
---|
| | from postorius.auth.decorators import (list_owner_required, |
---|
| | list_moderator_required, |
---|
| | superuser_or_403) |
---|
| | superuser_required) |
---|
| | from postorius.tests.utils import create_mock_list |
---|
| | from mailmanclient import Client |
---|
| | |
---|
| | |
---|
| |
---|
| | def dummy_function_mod_req(request, list_id): |
---|
| | return True |
---|
| | |
---|
| | |
---|
| | @superuser_or_403 |
---|
| | def dummy_superuser_or_403(request): |
---|
| | @superuser_required |
---|
| | def dummy_superuser_required(request): |
---|
| | return True |
---|
| | |
---|
| | |
---|
| | class ListOwnerRequiredTest(TestCase): |
---|
| |
---|
| | self.assertEqual(return_value, True) |
---|
| | |
---|
| | |
---|
| | class TestSuperUserOr403(TestCase): |
---|
| | """Tests superuser_or_403 auth decorator""" |
---|
| | """Tests superuser_required auth decorator""" |
---|
| | |
---|
| | def setUp(self): |
---|
| | self.request_factory = RequestFactory() |
---|
| | # create a mock list with members |
---|
| |
---|
| | |
---|
| | request = self.request_factory.get( |
---|
| | '/lists/foolist.example.org/settings/') |
---|
| | request.user = AnonymousUser() |
---|
| | self.assertRaises(PermissionDenied, dummy_superuser_or_403, request) |
---|
| | self.assertRaises(PermissionDenied, dummy_superuser_required, request) |
---|
| | |
---|
| | @patch.object(Client, 'get_list') |
---|
| | def test_normal_user(self, mock_get_list): |
---|
| | """Should raise PermissionDenied if user is a normal user.""" |
---|
| |
---|
| | request = self.request_factory.get( |
---|
| | '/lists/foolist.example.org/settings/') |
---|
| | request.user = User.objects.create_user( |
---|
| | 'new user', 'new@usersfactory.net', 'testing') |
---|
| | self.assertRaises(PermissionDenied, dummy_superuser_or_403, request) |
---|
| | self.assertRaises(PermissionDenied, dummy_superuser_required, request) |
---|
| | |
---|
| | @patch.object(Client, 'get_list') |
---|
| | def test_super_user(self, mock_get_list): |
---|
| | """Should not raise PermissionDenied if user is superuser.""" |
---|
| |
---|
| | request = self.request_factory.get( |
---|
| | '/lists/foolist.example.org/settings/') |
---|
| | request.user = User.objects.create_superuser( |
---|
| | 'new su', 'new@su.net', 'testing') |
---|
| | self.assertTrue(dummy_superuser_or_403(request)) |
---|
| | |
---|
| | self.assertTrue(dummy_superuser_required(request)) |
---|
| | |
---|
| | |