forked from rero/rero-ils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
circulation: manage non-circulating libraries
In older versions, the transaction locations of a library are selected from the list of pickup locations of the library. This causes a problem for libraries have not setup a pickup location. With this commit, for libraries with no pickup locations the system considers the first library location as transaction location for circulation transactions. * Fixes problem when checkout of items of libraries with no opening hours was no possible. * Allows requests on items of non-circulating libraries at external locations. * Closes rero#2367 * Adds a non-circulating library to units testing. Co-Authored-by: Aly Badr <aly.badr@rero.ch>
- Loading branch information
Aly Badr
committed
Oct 7, 2021
1 parent
5b13154
commit 1c7eb72
Showing
9 changed files
with
332 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
tests/api/circulation/test_library_with_no_circulation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# RERO ILS | ||
# Copyright (C) 2020 RERO | ||
# | ||
# 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/>. | ||
|
||
"""Tests REST checkout API methods in library with no circulation.""" | ||
|
||
from invenio_accounts.testutils import login_user_via_session | ||
from utils import postdata | ||
|
||
from rero_ils.modules.loans.api import Loan, LoanState | ||
|
||
|
||
def test_requesting_item_from_non_circulating_library( | ||
client, librarian_martigny, lib_martigny, lib_martigny_bourg, | ||
patron_martigny, loc_public_martigny, loc_public_martigny_bourg, | ||
item_lib_martigny_bourg, circulation_policies, | ||
librarian_martigny_bourg): | ||
"""Test requests at non circulating library.""" | ||
# TEST: a librarian from an external library can request and item from a | ||
# non-circulation library to be picked-up at his own library. | ||
login_user_via_session(client, librarian_martigny.user) | ||
res, data = postdata( | ||
client, | ||
'api_item.librarian_request', | ||
dict( | ||
item_pid=item_lib_martigny_bourg.pid, | ||
patron_pid=patron_martigny.pid, | ||
pickup_location_pid=loc_public_martigny.pid, | ||
transaction_library_pid=lib_martigny_bourg.pid, | ||
transaction_user_pid=librarian_martigny.pid | ||
) | ||
) | ||
assert res.status_code == 200 | ||
loan = data.get('metadata').get('pending_loans')[0] | ||
assert loan.get('transaction_location_pid') == \ | ||
loc_public_martigny_bourg.pid | ||
assert loan.get('pickup_location_pid') == loc_public_martigny.pid | ||
|
||
# non-circulating library send items to requesting library | ||
login_user_via_session(client, librarian_martigny_bourg.user) | ||
res, data = postdata( | ||
client, | ||
'api_item.validate_request', | ||
dict( | ||
pid=loan.get('pid'), | ||
transaction_library_pid=lib_martigny_bourg.pid, | ||
transaction_user_pid=librarian_martigny_bourg.pid | ||
) | ||
) | ||
assert res.status_code == 200 | ||
loan = data.get('metadata').get('pending_loans')[0] | ||
assert loan.get('transaction_location_pid') == \ | ||
loc_public_martigny_bourg.pid | ||
assert loan.get('pickup_location_pid') == loc_public_martigny.pid | ||
assert loan.get('state') == LoanState.ITEM_IN_TRANSIT_FOR_PICKUP | ||
|
||
# requesting library receives an item from non-circulating library. | ||
login_user_via_session(client, librarian_martigny.user) | ||
res, data = postdata( | ||
client, | ||
'api_item.receive', | ||
dict( | ||
pid=loan.get('pid'), | ||
transaction_library_pid=lib_martigny.pid, | ||
transaction_user_pid=librarian_martigny.pid | ||
) | ||
) | ||
assert res.status_code == 200 | ||
loan = data.get('metadata').get('pending_loans')[0] | ||
assert loan.get('transaction_location_pid') == \ | ||
loc_public_martigny.pid | ||
assert loan.get('pickup_location_pid') == loc_public_martigny.pid | ||
assert loan.get('state') == LoanState.ITEM_AT_DESK | ||
|
||
# checkout item to requested patron | ||
login_user_via_session(client, librarian_martigny.user) | ||
params = dict( | ||
item_pid=item_lib_martigny_bourg.pid, | ||
patron_pid=patron_martigny.pid, | ||
transaction_user_pid=librarian_martigny.pid, | ||
transaction_library_pid=lib_martigny.pid, | ||
) | ||
res, data = postdata( | ||
client, | ||
'api_item.checkout', | ||
params | ||
) | ||
assert res.status_code == 200 | ||
loan_pid = data.get('action_applied').get('checkout').get('pid') | ||
loan = Loan.get_record_by_pid(loan_pid) | ||
assert loan.get('transaction_location_pid') == \ | ||
loc_public_martigny.pid | ||
assert loan.get('pickup_location_pid') == loc_public_martigny.pid | ||
assert loan.get('state') == LoanState.ITEM_ON_LOAN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.