Skip to content

Commit

Permalink
ci-po: allow 'less than one day' checkout
Browse files Browse the repository at this point in the history
* Changes minimum checkout duration to allow 'less than one day' checkouts.

Co-Authored-by: Alicia Zangger <alicia.zangger@rero.ch>
  • Loading branch information
Alicia Zangger committed Nov 20, 2020
1 parent 747b790 commit c49b589
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"title": "Checkout duration in days",
"description": "The duration of the checkout in days.",
"type": "integer",
"minimum": 1,
"minimum": 0,
"default": 7
},
"allow_requests": {
Expand Down
24 changes: 24 additions & 0 deletions tests/data/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,30 @@
"policy_library_level": false,
"is_default": false
},
"cipo7": {
"$schema": "https://ils.rero.ch/schemas/circ_policies/circ_policy-v0.0.1.json",
"pid": "cipo7",
"name": "Less than one day",
"description": "Less than one day.",
"organisation": {
"$ref": "https://ils.rero.ch/api/organisations/org1"
},
"allow_checkout": true,
"checkout_duration": 0,
"allow_requests": false,
"policy_library_level": false,
"is_default": false,
"settings": [
{
"patron_type": {
"$ref": "https://ils.rero.ch/api/patron_types/ptty2"
},
"item_type": {
"$ref": "https://ils.rero.ch/api/item_types/itty1"
}
}
]
},
"cont_pers": {
"$schema": "https://ils.rero.ch/schemas/contributions/contribution-v0.0.1.json",
"gnd": {
Expand Down
28 changes: 26 additions & 2 deletions tests/fixtures/organisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,22 +852,46 @@ def circ_policy_ebooks_sion(
return cipo


@pytest.fixture(scope="module")
def circ_policy_less_than_one_day_martigny_data(data):
"""Load short circ policy for organisation martigny."""
return deepcopy(data.get('cipo7'))


@pytest.fixture(scope="module")
def circ_policy_less_than_one_day_martigny(
app,
patron_type_adults_martigny,
item_type_standard_martigny,
circ_policy_less_than_one_day_martigny_data):
"""Create short circ policy for organisation martigny."""
cipo = CircPolicy.create(
data=circ_policy_less_than_one_day_martigny_data,
delete_pid=False,
dbcommit=True,
reindex=True)
flush_index(CircPoliciesSearch.Meta.index)
return cipo


@pytest.fixture(scope="module")
def circulation_policies(
circ_policy_default_martigny,
circ_policy_default_sion,
circ_policy_short_martigny,
circ_policy_temp_martigny,
circ_policy_ebooks_martigny,
circ_policy_ebooks_sion):
circ_policy_ebooks_sion,
circ_policy_less_than_one_day_martigny):
"""Load all circulation policies."""
return [
circ_policy_default_martigny,
circ_policy_default_sion,
circ_policy_short_martigny,
circ_policy_temp_martigny,
circ_policy_ebooks_martigny,
circ_policy_ebooks_sion
circ_policy_ebooks_sion,
circ_policy_less_than_one_day_martigny
]


Expand Down
43 changes: 43 additions & 0 deletions tests/ui/circulation/test_actions_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,46 @@ def test_checkout_on_item_in_transit_to_house_with_pending_loan(
assert checkout_item.status == ItemStatus.ON_LOAN
assert checkout_loan['state'] == LoanState.ITEM_ON_LOAN
assert checkout_item.number_of_requests() == 1 # pending loan remains


def test_less_than_one_day_checkout(
circ_policy_less_than_one_day_martigny,
patron2_martigny_no_email,
item_lib_martigny,
loc_public_martigny,
librarian_martigny_no_email,
item_on_shelf_martigny_patron_and_loan_pending):
"""Test checkout on an ON_SHELF item with 'less than one day' cipo."""
# Create a new item in ON_SHELF (without Loan)
data = deepcopy(item_lib_martigny)
data.pop('barcode')
data.setdefault('status', ItemStatus.ON_SHELF)
created_item = Item.create(
data=data, dbcommit=True, reindex=True, delete_pid=True)

# Check item is ON_SHELF and NO PENDING loan exist!
assert created_item.number_of_requests() == 0
assert created_item.status == ItemStatus.ON_SHELF
assert not created_item.is_requested_by_patron(
patron2_martigny_no_email.get('patron', {}).get('barcode'))

# the following tests the circulation action CHECKOUT_1_1
# an ON_SHELF item
# WITHOUT pending loan
# CAN be CHECKOUT for less than one day
params = {
'patron_pid': patron2_martigny_no_email.pid,
'transaction_location_pid': loc_public_martigny.pid,
'transaction_user_pid': librarian_martigny_no_email.pid,
'pickup_location_pid': loc_public_martigny.pid
}
onloan_item, actions = created_item.checkout(**params)
loan = Loan.get_record_by_pid(actions[LoanAction.CHECKOUT].get('pid'))
# Check loan is ITEM_ON_LOAN and item is ON_LOAN
assert onloan_item.number_of_requests() == 0
assert onloan_item.status == ItemStatus.ON_LOAN
assert loan['state'] == LoanState.ITEM_ON_LOAN

# Fetch a PENDING item and loan
pending_item, patron, loan = item_on_shelf_martigny_patron_and_loan_pending

0 comments on commit c49b589

Please sign in to comment.