Skip to content

Commit

Permalink
tests: fix patron expiration date
Browse files Browse the repository at this point in the history
The patron fixtures should have a variable expiration date to avoid circulation
errors.

Co-Authored-by: Johnny Mariéthoz <[email protected]>
  • Loading branch information
jma committed Sep 27, 2023
1 parent 8bbc162 commit 773fd9e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion tests/api/patrons/test_patrons_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ def test_patron_info(app, client, patron_martigny, librarian_martigny):
'fullname':
'Roduit, Louis',
'patron_types': [{
'expiration_date': '2023-10-07T00:00:00',
'expiration_date':
patron_martigny['patron']['expiration_date']+'T00:00:00',
'institution': 'org1',
'patron_type': 'patron-code'
}]
Expand Down
16 changes: 8 additions & 8 deletions tests/fixtures/circulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from invenio_circulation.search.api import LoansSearch
from invenio_db import db
from utils import create_patron, flush_index, \
item_record_to_a_specific_loan_state
item_record_to_a_specific_loan_state, patch_expiration_date

from rero_ils.modules.cli.fixtures import load_role_policies, \
load_system_role_policies
Expand Down Expand Up @@ -231,13 +231,13 @@ def librarian_fully(
@pytest.fixture(scope="module")
def patron_martigny_data(data):
"""Load Martigny patron data."""
return deepcopy(data.get('ptrn6'))
return deepcopy(patch_expiration_date(data.get('ptrn6')))


@pytest.fixture(scope="function")
def patron_martigny_data_tmp(data):
"""Load Martigny patron data scope function."""
return deepcopy(data.get('ptrn6'))
return deepcopy(patch_expiration_date(data.get('ptrn6')))


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -274,7 +274,7 @@ def librarian_patron_martigny(
@pytest.fixture(scope="module")
def patron2_martigny_data(data):
"""Load Martigny patron data."""
return deepcopy(data.get('ptrn7'))
return deepcopy(patch_expiration_date(data.get('ptrn7')))


@pytest.fixture(scope="module")
Expand All @@ -293,7 +293,7 @@ def patron2_martigny(
@pytest.fixture(scope="module")
def patron3_martigny_blocked_data(data):
"""Load Martigny blocked patron data."""
return deepcopy(data.get('ptrn11'))
return deepcopy(patch_expiration_date(data.get('ptrn11')))


@pytest.fixture(scope="module")
Expand All @@ -312,7 +312,7 @@ def patron3_martigny_blocked(
@pytest.fixture(scope="module")
def patron4_martigny_data(data):
"""Load Martigny patron data."""
return deepcopy(data.get('ptrn12'))
return deepcopy(patch_expiration_date((data.get('ptrn12'))))


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -373,13 +373,13 @@ def librarian_sion(
@pytest.fixture(scope="module")
def patron_sion_data(data):
"""Load Sion patron data."""
return deepcopy(data.get('ptrn10'))
return deepcopy(patch_expiration_date(data.get('ptrn10')))


@pytest.fixture(scope="function")
def patron_sion_data_tmp(data):
"""Load Sion patron data scope function."""
return deepcopy(data.get('ptrn10'))
return deepcopy(patch_expiration_date(data.get('ptrn10')))


@pytest.fixture(scope="module")
Expand Down
11 changes: 10 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import csv
import json
from copy import deepcopy
from datetime import datetime, timezone
from datetime import datetime, timezone, timedelta

import jsonref
import requests
Expand Down Expand Up @@ -447,3 +447,12 @@ def create_selfcheck_terminal(data):
selfcheck_terminal = SelfcheckTerminal(**data)
db.session.add(selfcheck_terminal)
return selfcheck_terminal


def patch_expiration_date(data):
"""Patch expiration date for patrons."""
if data.get('patron', {}).get('expiration_date'):
# expiration date in one year
data['patron']['expiration_date'] = \
(datetime.now() + timedelta(days=365)).strftime('%Y-%m-%d')
return data

0 comments on commit 773fd9e

Please sign in to comment.