Ejemplo n.º 1
0
def test_recall_notification_without_email(
        client, patron_sion_without_email1, lib_martigny, json_header,
        patron2_martigny, item3_lib_martigny, librarian_martigny,
        circulation_policies, loc_public_martigny, mailbox):
    """Test recall notification."""
    mailbox.clear()
    login_user_via_session(client, librarian_martigny.user)
    res, data = postdata(
        client, 'api_item.checkout',
        dict(
            item_pid=item3_lib_martigny.pid,
            patron_pid=patron_sion_without_email1.pid,
            transaction_location_pid=loc_public_martigny.pid,
            transaction_user_pid=librarian_martigny.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=Notification.RECALL_NOTIFICATION_TYPE)
    # 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.pid,
             transaction_library_pid=lib_martigny.pid,
             transaction_user_pid=librarian_martigny.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=Notification.RECALL_NOTIFICATION_TYPE)
    notification = get_notification(
        loan, notification_type=Notification.RECALL_NOTIFICATION_TYPE)
    assert notification.loan_pid == loan.pid
    assert not loan.is_notified(
        notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)
    assert not get_notification(
        loan, notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)

    # one new email for the librarian
    assert mailbox[0].recipients == [
        lib_martigny.email_notification_type(notification['notification_type'])
    ]
    mailbox.clear()
Ejemplo n.º 2
0
def test_availability_notification(loan_validated_martigny, item2_lib_martigny,
                                   patron_martigny):
    """Test availability notification created from a loan."""
    loan = loan_validated_martigny
    assert loan.is_notified(
        notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)
    notification = get_notification(
        loan_validated_martigny,
        notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)
    assert notification.loan_pid == loan_validated_martigny.get('pid')
    assert notification.item_pid == item2_lib_martigny.pid
    assert notification.patron_pid == patron_martigny.pid

    assert not loan_validated_martigny.is_notified(
        notification_type=Notification.RECALL_NOTIFICATION_TYPE)
    assert not get_notification(
        loan_validated_martigny,
        notification_type=Notification.RECALL_NOTIFICATION_TYPE)
Ejemplo n.º 3
0
def notification_availability_sion(loan_validated_sion):
    """Availability notification of sion."""
    return get_notification(
        loan_validated_sion,
        notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)
Ejemplo n.º 4
0
def test_recall_notification(client, patron_sion, lib_sion, json_header,
                             patron_sion_without_email1, item_lib_sion,
                             librarian_sion, circulation_policies,
                             loc_public_sion, mailbox):
    """Test recall notification."""
    mailbox.clear()
    login_user_via_session(client, librarian_sion.user)
    res, data = postdata(
        client, 'api_item.checkout',
        dict(
            item_pid=item_lib_sion.pid,
            patron_pid=patron_sion.pid,
            transaction_location_pid=loc_public_sion.pid,
            transaction_user_pid=librarian_sion.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=Notification.RECALL_NOTIFICATION_TYPE)
    # test notification permissions
    res, data = postdata(
        client, 'api_item.librarian_request',
        dict(item_pid=item_lib_sion.pid,
             pickup_location_pid=loc_public_sion.pid,
             patron_pid=patron_sion_without_email1.pid,
             transaction_library_pid=lib_sion.pid,
             transaction_user_pid=librarian_sion.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=Notification.RECALL_NOTIFICATION_TYPE)
    notification = get_notification(
        loan, notification_type=Notification.RECALL_NOTIFICATION_TYPE)
    assert notification.loan_pid == loan.pid
    assert not loan.is_notified(
        notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)
    assert not get_notification(
        loan, notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)

    # one new email for the patron
    assert mailbox[0].recipients == [patron_sion.dumps()['email']]

    mailbox.clear()

    # cancel request
    res, _ = postdata(
        client, 'api_item.cancel_item_request',
        dict(item_pid=item_lib_sion.pid,
             pid=request_loan_pid,
             transaction_user_pid=librarian_sion.pid,
             transaction_location_pid=loc_public_sion.pid))
    assert res.status_code == 200

    # no new notification is send for the second time
    res, _ = postdata(
        client, 'api_item.librarian_request',
        dict(item_pid=item_lib_sion.pid,
             pickup_location_pid=loc_public_sion.pid,
             patron_pid=patron_sion_without_email1.pid,
             transaction_library_pid=lib_sion.pid,
             transaction_user_pid=librarian_sion.pid))
    assert res.status_code == 200

    flush_index(NotificationsSearch.Meta.index)

    assert loan.is_notified(
        notification_type=Notification.RECALL_NOTIFICATION_TYPE)
    notification = get_notification(
        loan, notification_type=Notification.RECALL_NOTIFICATION_TYPE)
    assert notification.loan_pid == loan.pid
    assert not loan.is_notified(
        notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)
    assert not get_notification(
        loan, notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)
    assert len(mailbox) == 0
Ejemplo n.º 5
0
def notification_availability_martigny(loan_validated_martigny):
    """Availability notification of martigny."""
    return get_notification(
        loan_validated_martigny,
        notification_type=Notification.AVAILABILITY_NOTIFICATION_TYPE)