diff --git a/rero_ils/modules/stats/views.py b/rero_ils/modules/stats/views.py index bb4a8eaa29..f5b0d0e76c 100644 --- a/rero_ils/modules/stats/views.py +++ b/rero_ils/modules/stats/views.py @@ -29,7 +29,7 @@ from elasticsearch_dsl import Q from flask import Blueprint, abort, make_response, render_template, request -from .api.api import Stat +from .api.api import Stat, StatsSearch from .api.pricing import StatsForPricing from .permissions import check_logged_as_admin, check_logged_as_librarian from .serializers import StatCSVSerializer diff --git a/tests/ui/stats/test_stats_views.py b/tests/ui/stats/test_stats_views.py new file mode 100644 index 0000000000..1f63965e1a --- /dev/null +++ b/tests/ui/stats/test_stats_views.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- +# +# RERO ILS +# Copyright (C) 2023 RERO +# Copyright (C) 2022 UCLouvain +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, version 3 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +"""Stats views tests.""" + +from __future__ import absolute_import, print_function + +import mock +from flask import url_for +from invenio_accounts.testutils import login_user_via_session + + +def test_view_status(client, patron_martigny, librarian_martigny): + """Test view status.""" + # User not logged + result = client.get(url_for('stats.stats_billing')) + assert result.status_code == 401 + + # User without access permissions + login_user_via_session(client, patron_martigny.user) + result = client.get(url_for('stats.stats_billing')) + assert result.status_code == 403 + + result = client.get(url_for('stats.live_stats_billing')) + assert result.status_code == 403 + + # User with librarian permissions + login_user_via_session(client, librarian_martigny.user) + result = client.get(url_for('stats.stats_billing')) + assert result.status_code == 403 + + result = client.get(url_for('stats.live_stats_billing')) + assert result.status_code == 403 + + result = client.get(url_for('stats.stats_librarian')) + assert result.status_code == 200 + + result = client.get(url_for('stats.stats_librarian', record_pid=1)) + assert result.status_code == 200 + + with mock.patch( + 'rero_ils.modules.stats.permissions.admin_permission', + mock.MagicMock() + ): + result = client.get(url_for('stats.stats_billing')) + assert result.status_code == 200