Ejemplo n.º 1
0
def user_patron_no_email_specific(
        app, roles, library, patron_type_specific, user_patron_data_specific):
    """."""
    ptrn = Patron.create(
        data=user_patron_data_specific,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(PatronsSearch.Meta.index)
    return ptrn
Ejemplo n.º 2
0
def item_specific(
        app, document, item_specific_data, location, item_type_specific):
    """."""
    item = Item.create(
        data=item_specific_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(ItemsSearch.Meta.index)
    return item
Ejemplo n.º 3
0
def ebook_4(app, ebook_4_data):
    """Load ebook 4 record."""
    del ebook_4_data['electronicLocator']
    doc = Document.create(
        data=ebook_4_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(DocumentsSearch.Meta.index)
    return doc
Ejemplo n.º 4
0
def user_patron(app, roles, library, user_librarian_type,
                user_patron_data):
    """."""
    ptrn = Patron.create(
        data=user_patron_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(PatronsSearch.Meta.index)
    return ptrn
Ejemplo n.º 5
0
def holding_lib_fully(app, document, holding_lib_fully_data,
                      loc_public_fully, item_type_standard_martigny):
    """Create holding of fully library."""
    holding = Holding.create(
        data=holding_lib_fully_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(HoldingsSearch.Meta.index)
    return holding
Ejemplo n.º 6
0
def holding_lib_sion(app, document, holding_lib_sion_data,
                     loc_public_sion, item_type_internal_sion):
    """Create holding of sion library."""
    holding = Holding.create(
        data=holding_lib_sion_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(HoldingsSearch.Meta.index)
    return holding
Ejemplo n.º 7
0
def circ_policy_default_sion(
        app, org_sion, lib_sion, circ_policy_default_sion_data):
    """Create default circ policy for organisation sion."""
    cipo = CircPolicy.create(
        data=circ_policy_default_sion_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(CircPoliciesSearch.Meta.index)
    return cipo
Ejemplo n.º 8
0
def patron_type_grown_sion(
        app, org_sion, patron_type_grown_sion_data):
    """Crate grown patron type of sion."""
    ptty = PatronType.create(
        data=patron_type_grown_sion_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(PatronTypesSearch.Meta.index)
    return ptty
Ejemplo n.º 9
0
def patron_type_adults_martigny(
        app, org_martigny, patron_type_adults_martigny_data):
    """Create adults patron type of martigny."""
    ptty = PatronType.create(
        data=patron_type_adults_martigny_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(PatronTypesSearch.Meta.index)
    return ptty
Ejemplo n.º 10
0
def item_lib_martigny_bourg(app, document, item_lib_martigny_bourg_data,
                            loc_public_martigny_bourg,
                            item_type_standard_martigny):
    """Create item of martigny library bourg."""
    item = Item.create(data=item_lib_martigny_bourg_data,
                       delete_pid=False,
                       dbcommit=True,
                       reindex=True)
    flush_index(ItemsSearch.Meta.index)
    return item
Ejemplo n.º 11
0
def templ_doc_private_martigny(app, org_martigny,
                               templ_doc_private_martigny_data,
                               librarian_martigny_no_email):
    """Create template for a private document martigny."""
    template = Template.create(data=templ_doc_private_martigny_data,
                               delete_pid=False,
                               dbcommit=True,
                               reindex=True)
    flush_index(TemplatesSearch.Meta.index)
    return template
Ejemplo n.º 12
0
def item_type_specific_martigny(
        app, org_martigny, item_type_specific_martigny_data):
    """Create specific item type of martigny."""
    itty = ItemType.create(
        data=item_type_specific_martigny_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(ItemTypesSearch.Meta.index)
    return itty
Ejemplo n.º 13
0
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
Ejemplo n.º 14
0
def templ_patron_public_martigny(app, org_martigny,
                                 templ_patron_public_martigny_data,
                                 system_librarian_martigny_no_email):
    """Load template for a public item martigny."""
    template = Template.create(data=templ_patron_public_martigny_data,
                               delete_pid=False,
                               dbcommit=True,
                               reindex=True)
    flush_index(TemplatesSearch.Meta.index)
    return template
Ejemplo n.º 15
0
def circ_policy_ebooks_sion(app, patron_type_youngsters_sion,
                            patron_type_grown_sion, item_type_online_sion,
                            circ_policy_ebooks_sion_data):
    """Create ebooks circ policy for organisation sion."""
    cipo = CircPolicy.create(data=circ_policy_ebooks_sion_data,
                             delete_pid=False,
                             dbcommit=True,
                             reindex=True)
    flush_index(CircPoliciesSearch.Meta.index)
    return cipo
Ejemplo n.º 16
0
def item_type_online_sion(
        app, org_sion, item_type_online_sion_data):
    """Create particular item type of sion."""
    itty = ItemType.create(
        data=item_type_online_sion_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(ItemTypesSearch.Meta.index)
    return itty
Ejemplo n.º 17
0
def test_location_pickup_locations(locations, patron_martigny_no_email,
                                   patron_sion_no_email, loc_public_martigny,
                                   item2_lib_martigny):
    """Test for pickup locations."""

    # At the beginning, if we load all locations from fixtures, there are 4
    # pickup locations (loc1, loc3, loc5, loc7)
    pickup_locations = Location.get_pickup_location_pids()
    assert set(pickup_locations) == set(['loc1', 'loc3', 'loc5', 'loc7'])

    # check pickup restrictions by patron_pid
    pickup_locations = Location.get_pickup_location_pids(
        patron_pid=patron_martigny_no_email.pid)
    assert set(pickup_locations) == set(['loc1', 'loc3', 'loc5'])
    pickup_locations = Location.get_pickup_location_pids(
        patron_pid=patron_sion_no_email.pid)
    assert set(pickup_locations) == set(['loc7'])

    # check pickup restrictions by item_barcode
    #   * update `loc1` to restrict_pickup_to 'loc3' and 'loc6'
    #     --> 'loc6' isn't a pickup location... it's just for test
    loc_public_martigny['restrict_pickup_to'] = [
        {'$ref': 'https://ils.rero.ch/api/locations/loc3'},
        {'$ref': 'https://ils.rero.ch/api/locations/loc6'},
    ]
    loc_public_martigny.update(
        loc_public_martigny,
        dbcommit=True,
        reindex=True
    )
    flush_index(LocationsSearch.Meta.index)
    pickup_locations = Location.get_pickup_location_pids(
        item_pid=item2_lib_martigny.pid)
    assert set(pickup_locations) == set(['loc3'])

    pickup_locations = Location.get_pickup_location_pids(
        patron_pid=patron_sion_no_email.pid,
        item_pid=item2_lib_martigny.pid)
    assert set(pickup_locations) == set([])

    # check document.views::item_library_pickup_locations
    #   As we limit pickup to two specific location, this tests will also
    #   return only these two records instead of all pickups for the
    #   organisation
    picks = item_library_pickup_locations(item2_lib_martigny)
    assert len(picks) == 2

    # reset the location to default value before leaving
    del loc_public_martigny['restrict_pickup_to']
    loc_public_martigny.update(
        loc_public_martigny,
        dbcommit=True,
        reindex=True
    )
    flush_index(LocationsSearch.Meta.index)
Ejemplo n.º 18
0
def test_items_no_extend(client, librarian_martigny, patron_martigny,
                         loc_public_martigny, item_type_standard_martigny,
                         item_lib_martigny, json_header,
                         circ_policy_short_martigny):
    """Test items when no renewals is possible."""
    login_user_via_session(client, librarian_martigny.user)
    item = item_lib_martigny
    item_pid = item.pid
    patron_pid = patron_martigny.pid
    location = loc_public_martigny

    # checkout
    res, data = postdata(
        client, 'api_item.checkout',
        dict(item_pid=item_pid,
             patron_pid=patron_pid,
             transaction_user_pid=librarian_martigny.pid,
             transaction_location_pid=loc_public_martigny.pid))
    assert res.status_code == 200
    actions = data.get('action_applied')
    loan_pid = actions[LoanAction.CHECKOUT].get('pid')
    assert not item.get_extension_count()

    circ_policy_short_martigny['number_renewals'] = 0

    circ_policy_short_martigny.update(data=circ_policy_short_martigny,
                                      dbcommit=True,
                                      reindex=True)
    flush_index(CircPoliciesSearch.Meta.index)

    # extend loan
    res, _ = postdata(
        client, 'api_item.extend_loan',
        dict(item_pid=item_pid,
             pid=loan_pid,
             transaction_user_pid=librarian_martigny.pid,
             transaction_location_pid=loc_public_martigny.pid))

    assert res.status_code == 403

    circ_policy_short_martigny['number_renewals'] = 1

    circ_policy_short_martigny.update(data=circ_policy_short_martigny,
                                      dbcommit=True,
                                      reindex=True)
    flush_index(CircPoliciesSearch.Meta.index)

    # checkin
    res, _ = postdata(
        client, 'api_item.checkin',
        dict(item_pid=item_pid,
             pid=loan_pid,
             transaction_user_pid=librarian_martigny.pid,
             transaction_location_pid=loc_public_martigny.pid))
    assert res.status_code == 200
Ejemplo n.º 19
0
def acq_invoice_fiction_sion(app, lib_sion, vendor_sion,
                             acq_invoice_fiction_sion_data,
                             acq_order_fiction_sion,
                             acq_order_line_fiction_sion):
    """Load acq_invoice lib sion fiction record."""
    acin = AcquisitionInvoice.create(data=acq_invoice_fiction_sion_data,
                                     delete_pid=False,
                                     dbcommit=True,
                                     reindex=True)
    flush_index(AcquisitionInvoicesSearch.Meta.index)
    return acin
Ejemplo n.º 20
0
def acq_receipt_fiction_sion(app, lib_sion, vendor_sion,
                             acq_order_fiction_sion,
                             acq_receipt_fiction_sion_data,
                             acq_account_fiction_sion):
    """Load acq_receipt lib sion fiction record."""
    acor = AcqReceipt.create(data=acq_receipt_fiction_sion_data,
                             delete_pid=False,
                             dbcommit=True,
                             reindex=True)
    flush_index(AcqReceiptsSearch.Meta.index)
    return acor
Ejemplo n.º 21
0
def holding_lib_martigny_w_patterns(app, journal,
                                    holding_lib_martigny_w_patterns_data,
                                    loc_public_martigny,
                                    item_type_standard_martigny):
    """Create holding of martigny library with patterns."""
    holding = Holding.create(data=holding_lib_martigny_w_patterns_data,
                             delete_pid=False,
                             dbcommit=True,
                             reindex=True)
    flush_index(HoldingsSearch.Meta.index)
    return holding
Ejemplo n.º 22
0
def document2_ref(mock_persons_mef_get, app, document2_data_ref,
                  person2_response_data):
    """Load document with mef records reference."""
    mock_persons_mef_get.return_value = mock_response(
        json_data=person2_response_data)
    doc = Document.create(data=document2_data_ref,
                          delete_pid=False,
                          dbcommit=True,
                          reindex=True)
    flush_index(DocumentsSearch.Meta.index)
    return doc
Ejemplo n.º 23
0
def sip2_patron_martigny_no_email(app, roles, patron_type_children_martigny,
                                  sip2_patron_martigny_data):
    """Create Martigny patron without sending reset password instruction."""
    # create patron account
    patron = Patron.create(data=sip2_patron_martigny_data,
                           delete_pid=False,
                           dbcommit=True,
                           reindex=True)

    flush_index(PatronsSearch.Meta.index)
    return patron
Ejemplo n.º 24
0
def test_overdue_loans(client, librarian_martigny_no_email,
                       patron_martigny_no_email, loc_public_martigny,
                       item_type_standard_martigny,
                       item_lib_martigny,
                       circ_policy_short_martigny):
    """Test overdue loans."""
    login_user_via_session(client, librarian_martigny_no_email.user)
    item = item_lib_martigny
    item_pid = item.pid
    patron_pid = patron_martigny_no_email.pid

    # checkout
    res, data = postdata(
        client,
        'api_item.checkout',
        dict(
            item_pid=item_pid,
            patron_pid=patron_pid
        )
    )
    assert res.status_code == 200, "It probably failed while \
        test_due_soon_loans fail"

    loan_pid = data.get('action_applied')[LoanAction.CHECKOUT].get('pid')
    loan = Loan.get_record_by_pid(loan_pid)
    end_date = datetime.now(timezone.utc) - timedelta(days=7)
    loan['end_date'] = end_date.isoformat()
    loan.update(
        loan,
        dbcommit=True,
        reindex=True
    )

    overdue_loans = get_overdue_loans()
    assert overdue_loans[0].get('pid') == loan_pid

    assert number_of_reminders_sent(loan) == 0

    loan.create_notification(notification_type='overdue')
    flush_index(NotificationsSearch.Meta.index)
    flush_index(LoansSearch.Meta.index)

    assert number_of_reminders_sent(loan) == 1

    # checkin the item to put it back to it's original state
    res, _ = postdata(
        client,
        'api_item.checkin',
        dict(
            item_pid=item_pid,
            pid=loan_pid
        )
    )
    assert res.status_code == 200
Ejemplo n.º 25
0
def test_recall_notification_without_email(
        client, patron_sion_without_email, lib_martigny, json_header,
        patron2_martigny_no_email, item3_lib_martigny,
        librarian_martigny_no_email, circulation_policies, loc_public_martigny,
        mailbox):
    """Test recall notification."""
    # process all notifications still in the queue
    Notification.process_notifications()
    mailbox.clear()
    login_user_via_session(client, librarian_martigny_no_email.user)
    res, data = postdata(
        client, 'api_item.checkout',
        dict(
            item_pid=item3_lib_martigny.pid,
            patron_pid=patron_sion_without_email.pid,
            transaction_location_pid=loc_public_martigny.pid,
            transaction_user_pid=librarian_martigny_no_email.pid,
        ))
    assert res.status_code == 200
    loan_pid = data.get('action_applied')[LoanAction.CHECKOUT].get('pid')
    loan = Loan.get_record_by_pid(loan_pid)

    assert not loan.is_notified(notification_type='recall')
    # test notification
    res, data = postdata(
        client, 'api_item.librarian_request',
        dict(item_pid=item3_lib_martigny.pid,
             pickup_location_pid=loc_public_martigny.pid,
             patron_pid=patron2_martigny_no_email.pid,
             transaction_library_pid=lib_martigny.pid,
             transaction_user_pid=librarian_martigny_no_email.pid))
    assert res.status_code == 200

    request_loan_pid = data.get('action_applied')[LoanAction.REQUEST].get(
        'pid')

    flush_index(NotificationsSearch.Meta.index)

    assert loan.is_notified(notification_type='recall')

    notification = get_recall_notification(loan)
    assert notification.loan_pid == loan.pid

    assert not loan.is_notified(notification_type='availability')
    assert not get_availability_notification(loan)
    assert Notification.process_notifications() == {
        'send': 1,
        'reject': 0,
        'error': 0
    }

    # no email as the patron does not have an email
    assert len(mailbox) == 0
    mailbox.clear()
Ejemplo n.º 26
0
def circ_policy_ebooks_martigny(app, patron_type_adults_martigny,
                                patron_type_children_martigny,
                                item_type_online_martigny,
                                circ_policy_ebooks_martigny_data):
    """Create ebooks circ policy for organisation martigny."""
    cipo = CircPolicy.create(data=circ_policy_ebooks_martigny_data,
                             delete_pid=False,
                             dbcommit=True,
                             reindex=True)
    flush_index(CircPoliciesSearch.Meta.index)
    return cipo
Ejemplo n.º 27
0
def test_loan_utils(client, patron_martigny_no_email,
                    patron2_martigny_no_email, circulation_policies,
                    loan_pending_martigny, item_lib_martigny,
                    loc_public_martigny):
    """Test loan utils."""
    loan_metadata = dict(item_lib_martigny)
    if 'item_pid' not in loan_metadata:
        loan_metadata['item_pid'] = item_lib_martigny.pid
    if 'patron_pid' not in loan_metadata:
        loan_metadata['patron_pid'] = patron_martigny_no_email.pid
    # Create "virtual" Loan (not registered)
    loan = Loan(loan_metadata)
    assert can_be_requested(loan)

    del loan['item_pid']
    with pytest.raises(Exception):
        assert can_be_requested(loan)

    assert loan_pending_martigny.patron_pid == patron2_martigny_no_email.pid
    assert not loan_pending_martigny.is_active

    with pytest.raises(TypeError):
        assert get_loans_by_patron_pid()
    assert get_loans_by_patron_pid(patron2_martigny_no_email.pid)

    with pytest.raises(TypeError):
        assert get_last_transaction_loc_for_item()

    assert loan_pending_martigny.organisation_pid

    new_loan = deepcopy(loan_pending_martigny)
    assert new_loan.organisation_pid
    del new_loan['item_pid']
    with pytest.raises(IlsRecordError.PidDoesNotExist):
        new_loan.organisation_pid

    new_loan = deepcopy(loan_pending_martigny)
    assert can_be_requested(new_loan)
    loc_public_martigny['allow_request'] = False
    loc_public_martigny.update(
        loc_public_martigny,
        dbcommit=True,
        reindex=True
    )
    flush_index(LocationsSearch.Meta.index)
    assert not can_be_requested(new_loan)

    loc_public_martigny['allow_request'] = True
    loc_public_martigny.update(
        loc_public_martigny,
        dbcommit=True,
        reindex=True
    )
    flush_index(LocationsSearch.Meta.index)
Ejemplo n.º 28
0
def test_holding_item_links(client, holding_lib_martigny, item_lib_martigny,
                            item_lib_martigny_data, document,
                            item_type_on_site_martigny, loc_public_martigny,
                            item_lib_saxon_data, loc_public_saxon,
                            item_type_standard_martigny):
    """Test holding and item links."""
    item = deepcopy(item_lib_martigny_data)
    del item['pid']
    item['barcode'] = 'barcode'
    item = Item.create(item, dbcommit=True, reindex=True)
    flush_index(HoldingsSearch.Meta.index)
    assert item.holding_pid == holding_lib_martigny.pid
    assert item.holding_circulation_category_pid == \
        item_type_standard_martigny.pid

    item2 = deepcopy(item_lib_saxon_data)
    del item2['pid']
    item2 = Item.create(item2, dbcommit=True, reindex=True)
    flush_index(HoldingsSearch.Meta.index)
    assert item2.holding_pid != holding_lib_martigny.pid

    holding = Holding.get_record_by_pid(item2.holding_pid)
    assert holding.document_pid == document.pid
    assert holding.circulation_category_pid == item_type_standard_martigny.pid

    assert Holding.get_document_pid_by_holding_pid(item2.holding_pid) == \
        document.pid

    holdings = list(Holding.get_holdings_pid_by_document_pid(document.pid))
    assert holding_lib_martigny.pid in holdings
    assert item2.holding_pid in holdings

    assert holding_lib_martigny.get_links_to_me().get('items')
    assert not holding_lib_martigny.can_delete
    # test loan conditions
    assert holding_loan_condition_filter(holding_lib_martigny.pid) == \
        'standard'
    with pytest.raises(Exception):
        assert holding_loan_condition_filter('no pid')
    assert holding_location(holding_lib_martigny.replace_refs()) == \
        'Library of Martigny-ville: Martigny Library Public Space'
    assert holding_circulation_category(holding_lib_martigny) == 'standard'
    holdings = get_holdings_by_document_item_type(
        document.pid, item_type_standard_martigny.pid)
    assert holding_lib_martigny.pid == holdings[1].get('pid')
    assert list(holding_lib_martigny.get_items)[1].get('pid') == \
        item_lib_martigny.pid

    holding_lib_martigny.delete_from_index()
    assert not holding_lib_martigny.delete_from_index()
    holding_lib_martigny.dbcommit(forceindex=True)

    # test item count by holdings pid
    assert holding_lib_martigny.get_items_count_by_holding_pid == 2
Ejemplo n.º 29
0
def coll_saxon_1(
        app, org_martigny, lib_saxon, coll_saxon_1_data, item2_lib_martigny,
        item_lib_martigny):
    """Create collection Saxon 1."""
    coll = Collection.create(
        data=coll_saxon_1_data,
        delete_pid=False,
        dbcommit=True,
        reindex=True)
    flush_index(CollectionsSearch.Meta.index)
    return coll
Ejemplo n.º 30
0
def test_collection_enrich_data(client, document, item_type_standard_martigny,
                                item_lib_martigny, item2_lib_martigny,
                                loc_public_martigny, coll_martigny_1,
                                json_header):
    """Test record retrieval."""
    coll_martigny_1.reindex()
    flush_index(CollectionsSearch.Meta.index)
    query = CollectionsSearch().filter(
        'term', pid=coll_martigny_1.pid).source().scan()
    coll_martigny_1_es_data = next(query)
    assert coll_martigny_1_es_data.organisation.pid == 'org1'