Exemplo n.º 1
0
    def test_has_perm_in_list(self):
        anonymous = AnonymousUser()
        anonymous.get_all_permissions = MagicMock(return_value=('p1', 'p2'))

        self.assertTrue(
            anonymous.has_perm('p1'),
            "has_perm() should return True when the user has the permission")
Exemplo n.º 2
0
    def test_has_perm_not_in_list(self):
        anonymous = AnonymousUser()
        anonymous.get_all_permissions = MagicMock(return_value=("p1", "p2"))

        self.assertFalse(
            anonymous.has_perm("p3"), "has_perm() should return False when the user has not the permission"
        )
Exemplo n.º 3
0
    def test_has_module_perms_not_in_list(self):
        anonymous = AnonymousUser()
        anonymous.get_all_permissions = MagicMock(return_value=("test_otherapp.perm",))

        self.assertFalse(
            anonymous.has_module_perms("test_app"),
            "has_module_perms() should return False when the user does not have " "the permission test_app.perm",
        )
Exemplo n.º 4
0
    def test_has_module_perms_in_list(self):
        anonymous = AnonymousUser()
        anonymous.get_all_permissions = MagicMock(return_value=("test_app.perm",))

        self.assertTrue(
            anonymous.has_module_perms("test_app"),
            "has_module_perms() should return True when the user has the " "permission test_app.perm",
        )
Exemplo n.º 5
0
    def test_has_module_perms_not_in_list(self):
        anonymous = AnonymousUser()
        anonymous.get_all_permissions = MagicMock(
            return_value=('test_otherapp.perm', ))

        self.assertFalse(
            anonymous.has_module_perms('test_app'),
            "has_module_perms() should return False when the user does not have "
            "the permission test_app.perm")
Exemplo n.º 6
0
    def test_has_module_perms_in_list(self):
        anonymous = AnonymousUser()
        anonymous.get_all_permissions = MagicMock(
            return_value=('test_app.perm', ))

        self.assertTrue(
            anonymous.has_module_perms('test_app'),
            "has_module_perms() should return True when the user has the "
            "permission test_app.perm")
Exemplo n.º 7
0
    def test_get_all_permissions_from_group_1(self):
        """
        Tests, that get_all_permissions looks in the permissions of the group with
        pk=1
        """
        anonymous = AnonymousUser()

        with patch('openslides.users.auth.Permission') as mock_permission:
            anonymous.get_all_permissions()

        mock_permission.objects.filter.assert_called_once_with(group__pk=1)
Exemplo n.º 8
0
    def test_not_in_cache(self, mock_get_user, mock_config):
        mock_config.__getitem__.return_value = True
        mock_get_user.return_value = AnonymousUser()
        request = MagicMock()
        del request._cached_user

        user = get_user(request)

        mock_get_user.assert_called_once_with(request)
        self.assertEqual(user, AnonymousUser())
        self.assertEqual(request._cached_user, AnonymousUser())
Exemplo n.º 9
0
    def test_get_all_permissions_from_group_1(self):
        """
        Tests, that get_all_permissions looks in the permissions of the group with
        pk=1
        """
        anonymous = AnonymousUser()

        with patch("openslides.users.auth.Permission") as mock_permission:
            anonymous.get_all_permissions()

        mock_permission.objects.filter.assert_called_once_with(group__pk=1)
Exemplo n.º 10
0
    def test_anonymous_disabled(self, mock_auth, mock_config):
        mock_config.__getitem__.return_value = False
        request = MagicMock()
        mock_auth.return_value = {'user': AnonymousUser()}

        context = auth(request)

        self.assertEqual(context, {
            'user': AnonymousUser(),
            'os_enable_anonymous_login': False
        })