Exemplo n.º 1
0
    def test_app_access_has_permission(self, mock_app, mock_has_perm):
        mock_app.return_value = mock.MagicMock(enabled=True)
        mock_request = mock.MagicMock()

        obj = TethysAppAccessMiddleware(mock_request)
        obj.__call__(mock_request)

        self.assertEqual(mock_has_perm.call_args_list[0][0][1], mock_app())
Exemplo n.º 2
0
    def test_app_access_app_none(self, mock_app):
        mock_app.return_value = None
        mock_request = mock.MagicMock()
        mock_request.return_value = True

        obj = TethysAppAccessMiddleware(mock_request)
        result = obj.__call__(mock_request)

        self.assertTrue(result)
Exemplo n.º 3
0
    def test_app_access_disabled(self, mock_app, mock_404):
        mock_app.return_value = mock.MagicMock(enabled=False)
        mock_request1 = mock.MagicMock()

        obj1 = TethysAppAccessMiddleware(mock_request1)
        obj1.__call__(mock_request1)

        self.assertEqual(
            mock_404.call_args_list[0][0][2],
            "This app is disabled. A user with admin permissions can "
            "enable this app from the app settings page.")

        mock_request2 = mock.MagicMock()
        mock_request2.user.is_staff = False

        obj2 = TethysAppAccessMiddleware(mock_request2)
        obj2.__call__(mock_request2)

        self.assertEqual(mock_404.call_args_list[0][0][1], PermissionDenied)