Skip to content

Commit

Permalink
stats: add tests
Browse files Browse the repository at this point in the history
* Splits the classes to compute statistics into several files.
* Fixes some spelling.
* Renames abstract class which is not abstract.
* Removes useless parameters in the statics methods.
* Get the location names using only one es query.
* Creates a loan search query used for several statistics.
* Fixes delete items statistics.
* Adds tests for statistics.
* Fixes some test fixtures.
* Adds a type filter to the operation logs search to avoid unwanted documents.

Co-Authored-by: Johnny Mariéthoz <[email protected]>
Co-Authored-by: Bertrand Zuchuat <[email protected]>
  • Loading branch information
jma and Garfield-fr committed Sep 20, 2023
1 parent 770dc5e commit 589aa36
Show file tree
Hide file tree
Showing 19 changed files with 1,137 additions and 729 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ patron_id = "rero_ils.modules.patrons.api:patron_id_fetcher"
patron_transaction_event_id = "rero_ils.modules.patron_transaction_events.api:patron_transaction_event_id_fetcher"
patron_transaction_id = "rero_ils.modules.patron_transactions.api:patron_transaction_id_fetcher"
patron_type_id = "rero_ils.modules.patron_types.api:patron_type_id_fetcher"
stat_id = "rero_ils.modules.stats.api:stat_id_fetcher"
stat_id = "rero_ils.modules.stats.api.api:stat_id_fetcher"
template_id = "rero_ils.modules.templates.api:template_id_fetcher"
entity_id = "rero_ils.modules.entities.fetchers:id_fetcher"
vendor_id = "rero_ils.modules.vendors.api:vendor_id_fetcher"
Expand Down Expand Up @@ -360,7 +360,7 @@ patron_id = "rero_ils.modules.patrons.api:patron_id_minter"
patron_transaction_event_id = "rero_ils.modules.patron_transaction_events.api:patron_transaction_event_id_minter"
patron_transaction_id = "rero_ils.modules.patron_transactions.api:patron_transaction_id_minter"
patron_type_id = "rero_ils.modules.patron_types.api:patron_type_id_minter"
stat_id = "rero_ils.modules.stats.api:stat_id_minter"
stat_id = "rero_ils.modules.stats.api.api:stat_id_minter"
template_id = "rero_ils.modules.templates.api:template_id_minter"
entity_id = "rero_ils.modules.entities.minters:id_minter"
vendor_id = "rero_ils.modules.vendors.api:vendor_id_minter"
Expand Down
14 changes: 7 additions & 7 deletions rero_ils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
from .modules.patrons.models import CommunicationChannel
from .modules.patrons.permissions import PatronPermissionPolicy
from .modules.selfcheck.permissions import seflcheck_permission_factory
from .modules.stats.api import Stat
from .modules.stats.api.api import Stat
from .modules.stats.permissions import StatisticsPermissionPolicy
from .modules.templates.permissions import TemplatePermissionPolicy
from .modules.users.api import get_profile_countries, \
Expand Down Expand Up @@ -773,9 +773,9 @@ def _(x):
pid_type='stat',
pid_minter='stat_id',
pid_fetcher='stat_id',
search_class='rero_ils.modules.stats.api:StatsSearch',
search_class='rero_ils.modules.stats.api.api:StatsSearch',
search_index='stats',
indexer_class='rero_ils.modules.stats.api:StatsIndexer',
indexer_class='rero_ils.modules.stats.api.api:StatsIndexer',
search_type=None,
record_serializers={
'application/json': 'rero_ils.modules.serializers:json_v1_response',
Expand All @@ -792,8 +792,8 @@ def _(x):
record_loaders={
'application/json': lambda: Stat(request.get_json()),
},
record_class='rero_ils.modules.stats.api:Stat',
item_route='/stats/<pid(stat, record_class="rero_ils.modules.stats.api:Stat"):pid_value>',
record_class='rero_ils.modules.stats.api.api:Stat',
item_route='/stats/<pid(stat, record_class="rero_ils.modules.stats.api.api:Stat"):pid_value>',
default_media_type='application/json',
max_result_window=MAX_RESULT_WINDOW,
list_permission_factory_imp=lambda record: StatisticsPermissionPolicy('search', record=record),
Expand Down Expand Up @@ -2829,7 +2829,7 @@ def _(x):
pid_type='stat',
route='/stats/<pid_value>',
template='rero_ils/detailed_view_stats.html',
record_class='rero_ils.modules.stats.api:Stat',
record_class='rero_ils.modules.stats.api.api:Stat',
view_imp='rero_ils.modules.stats.views.stats_view_method',
permission_factory_imp='rero_ils.modules.stats.permissions:stats_ui_permission_factory',
)
Expand Down Expand Up @@ -2897,7 +2897,7 @@ def _(x):
# Statistics Configuration
# ========================
# Compute the stats with a timeframe given in monthes
RERO_ILS_STATS_BILLING_TIMEFRAME_IN_MONTHES = 3
RERO_ILS_STATS_BILLING_TIMEFRAME_IN_MONTHS = 3


# =============================================================================
Expand Down
6 changes: 3 additions & 3 deletions rero_ils/modules/loans/logs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

from invenio_search import RecordsSearch

from rero_ils.modules.operation_logs.logs.api import \
AbstractSpecificOperationLog
from rero_ils.modules.operation_logs.api import OperationLog
from rero_ils.modules.operation_logs.logs.api import SpecificOperationLog

from ...items.api import Item
from ...patrons.api import Patron, current_librarian


class LoanOperationLog(AbstractSpecificOperationLog):
class LoanOperationLog(OperationLog, SpecificOperationLog):
"""Operation log for loans."""

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions rero_ils/modules/notifications/logs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

"""Notification logs API."""

from rero_ils.modules.operation_logs.logs.api import \
AbstractSpecificOperationLog
from rero_ils.modules.operation_logs.api import OperationLog
from rero_ils.modules.operation_logs.logs.api import SpecificOperationLog

from ..models import RecipientType


class NotificationOperationLog(AbstractSpecificOperationLog):
class NotificationOperationLog(OperationLog, SpecificOperationLog):
"""Operation log for notification."""

@classmethod
Expand Down
5 changes: 2 additions & 3 deletions rero_ils/modules/operation_logs/logs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
import hashlib

from rero_ils.modules.locations.api import Location
from rero_ils.modules.operation_logs.api import OperationLog
from rero_ils.modules.utils import extracted_data_from_ref


class AbstractSpecificOperationLog(OperationLog):
"""Abstract Specific Operation log."""
class SpecificOperationLog():
"""Specific Operation log."""

@classmethod
def _get_patron_data(cls, patron):
Expand Down
Loading

0 comments on commit 589aa36

Please sign in to comment.