Skip to content

Commit

Permalink
stats: add missing import for StatsSearch
Browse files Browse the repository at this point in the history
Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
Garfield-fr committed Oct 3, 2023
1 parent e3622a0 commit c6809eb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
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

0 comments on commit c6809eb

Please sign in to comment.