예제 #1
0
    def test_uses_custom_function(self, guardian_settings):
        path = 'guardian.testapp.tests.management_test.mocked_get_init_anon'
        guardian_settings.GET_INIT_ANONYMOUS_USER = path
        guardian_settings.ANONYMOUS_USER_ID = 219
        User = get_user_model()

        anon = mocked_get_init_anon.return_value = mock.Mock()

        create_anonymous_user('sender')

        mocked_get_init_anon.assert_called_once_with(User)

        self.assertEqual(anon.pk, 219)
        anon.save.assert_called_once_with()
예제 #2
0
 def test_user_manager_assign(self):
     manager = UserObjectPermissionManager()
     manager.assign_perm = mock.Mock()
     manager.assign('perm', 'user', 'object')
     manager.assign_perm.assert_called_once_with('perm', 'user', 'object')
예제 #3
0
 def test_group_manager_assign(self):
     manager = GroupObjectPermissionManager()
     manager.assign_perm = mock.Mock()
     manager.assign('perm', 'group', 'object')
     manager.assign_perm.assert_called_once_with('perm', 'group', 'object')
예제 #4
0
 class SecretView(TestView):
     on_permission_check_fail = mock.Mock()
예제 #5
0
from __future__ import absolute_import
from __future__ import unicode_literals

from guardian.compat import get_user_model
from guardian.compat import mock
from guardian.compat import unittest
from guardian.management import create_anonymous_user
import django


mocked_get_init_anon = mock.Mock()


class TestGetAnonymousUser(unittest.TestCase):

    @unittest.skipUnless(django.VERSION >= (1, 5), "Django >= 1.5 only")
    @mock.patch('guardian.management.guardian_settings')
    def test_uses_custom_function(self, guardian_settings):
        path = 'guardian.testapp.tests.management_test.mocked_get_init_anon'
        guardian_settings.GET_INIT_ANONYMOUS_USER = path
        guardian_settings.ANONYMOUS_USER_ID = 219
        User = get_user_model()

        anon = mocked_get_init_anon.return_value = mock.Mock()

        create_anonymous_user('sender')

        mocked_get_init_anon.assert_called_once_with(User)

        self.assertEqual(anon.pk, 219)
        anon.save.assert_called_once_with()