Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stats: add missing import for StatsSearch #3472

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rero_ils/modules/stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions tests/ui/stats/test_stats_views.py
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

"""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