def test_get_patron(patron_martigny_no_email): """Test patron retrieval.""" patron = patron_martigny_no_email assert Patron.get_patron_by_email(patron.get('email')) == patron assert not Patron.get_patron_by_email('not exists') assert Patron.get_patron_by_barcode(patron.get('barcode')) == patron assert not Patron.get_patron_by_barcode('not exists') class user: email = patron.get('email') assert Patron.get_patron_by_user(user) == patron
def test_get_patron(patron_martigny): """Test patron retrieval.""" patron = patron_martigny assert Patron.get_patron_by_email(patron.dumps().get('email')) == patron assert not Patron.get_patron_by_email('not exists') assert Patron.get_patron_by_barcode( patron.patron.get('barcode')[0]) == patron assert not Patron.get_patron_by_barcode('not exists') assert Patron.get_patrons_by_user(patron.user)[0] == patron class user: pass assert not Patron.get_patrons_by_user(user)
def can_request(holding_pid): """HTTP request to check if an holding can be requested. Depending of query string argument, check if either configuration allows the request of the holding or if a librarian can request an holding for a patron. `api/holding/<holding_pid>/can_request` : --> only check config `api/holding/<holding_pid>/can_request?library_pid=<library_pid>&patron_barcode=<barcode>`: --> check if the patron can request an holding (check the cipo) """ kwargs = {} holding = Holding.get_record_by_pid(holding_pid) if not holding: abort(404, 'Holding not found') patron_barcode = flask_request.args.get('patron_barcode') if patron_barcode: kwargs['patron'] = Patron.get_patron_by_barcode( patron_barcode, holding.organisation_pid) if not kwargs['patron']: abort(404, 'Patron not found') library_pid = flask_request.args.get('library_pid') if library_pid: kwargs['library'] = Library.get_record_by_pid(library_pid) if not kwargs['library']: abort(404, 'Library not found') can, reasons = holding.can(HoldingCirculationAction.REQUEST, **kwargs) # check the `reasons_not_request` array. If it's empty, the request is # allowed, otherwise the request is not allowed and we need to return the # reasons why response = {'can': can} if reasons: response['reasons'] = {'others': {reason: True for reason in reasons}} return jsonify(response)
def can_request(item_pid): """HTTP request to check if an item can be requested. Depending of query string argument, either only check if configuration allows the request of this item ; either if a librarian can request an item for a patron. `api/item/<item_pid>/can_request` : --> only check config `api/item/<item_pid>/can_request?library_pid=<library_pid>&patron_barcode=<barcode>`: --> check if the patron can request this item (check the cipo) """ kwargs = {} item = Item.get_record_by_pid(item_pid) if not item: abort(404, 'Item not found') patron_barcode = flask_request.args.get('patron_barcode') if patron_barcode: kwargs['patron'] = Patron.get_patron_by_barcode( patron_barcode, item.organisation_pid) if not kwargs['patron']: abort(404, 'Patron not found') library_pid = flask_request.args.get('library_pid') if library_pid: kwargs['library'] = Library.get_record_by_pid(library_pid) if not kwargs['library']: abort(404, 'Library not found') # ask to item if the request is possible with these data. can, reasons = item.can(ItemCirculationAction.REQUEST, **kwargs) # check the `reasons_not_request` array. If it's empty, the request is # allowed ; if not the request is disallow and we need to return the # reasons why response = {'can': can} if reasons: response['reasons'] = {'others': {reason: True for reason in reasons}} return jsonify(response)