def test_marcxml_documents_create(client, document_marcxml, documents_marcxml,
                                  rero_marcxml_header,
                                  librarian_martigny_no_email):
    """Test post of marcxml document for logged users."""
    res, data = postdata(client,
                         'invenio_records_rest.doc_list',
                         document_marcxml,
                         headers=rero_marcxml_header,
                         force_data_as_json=False)
    assert res.status_code == 401

    login_user_via_session(client, librarian_martigny_no_email.user)
    res, data = postdata(client,
                         'invenio_records_rest.doc_list',
                         document_marcxml,
                         headers=rero_marcxml_header,
                         force_data_as_json=False)
    assert res.status_code == 201
    assert data['metadata']['_draft']

    #  test fails when multiple xml records are sent.
    res, data = postdata(client,
                         'invenio_records_rest.doc_list',
                         documents_marcxml,
                         headers=rero_marcxml_header,
                         force_data_as_json=False)
    assert res.status_code == 400
Exemple #2
0
def test_patrons_search(
        client,
        librarian_martigny_no_email
):
    """Test document boosting."""
    login_user_via_session(client, librarian_martigny_no_email.user)
    birthdate = librarian_martigny_no_email.get('birth_date')
    # complete birthdate
    list_url = url_for(
        'invenio_records_rest.ptrn_list',
        q='{birthdate}'.format(birthdate=birthdate),
        simple='1'
    )
    res = client.get(list_url)
    hits = get_json(res)['hits']
    assert hits['total']['value'] == 1

    # birth year
    list_url = url_for(
        'invenio_records_rest.ptrn_list',
        q='{birthdate}'.format(birthdate=birthdate.split('-')[0]),
        simple='1'
    )
    res = client.get(list_url)
    hits = get_json(res)['hits']
    assert hits['total']['value'] == 1
def test_less_than_one_day_checkout(
        client,
        circ_policy_less_than_one_day_martigny,
        patron_martigny,
        patron2_martigny,
        item_lib_martigny,
        loc_public_martigny,
        librarian_martigny,
        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.get('patron', {}).get('barcode')[0])

    # Ensure than the transaction date used will be an open_day.
    owner_lib = Library.get_record_by_pid(created_item.library_pid)
    transaction_date = owner_lib.next_open(ensure=True)

    with freeze_time(transaction_date):
        # the following tests the circulation action CHECKOUT_1_1
        # an ON_SHELF item
        # WITHOUT pending loan
        # CAN be CHECKOUT for less than one day
        login_user_via_session(client, librarian_martigny.user)
        res, data = postdata(
            client,
            'api_item.checkout',
            dict(
                item_pid=created_item.pid,
                patron_pid=patron2_martigny.pid,
                transaction_location_pid=loc_public_martigny.pid,
                transaction_user_pid=librarian_martigny.pid,
                pickup_location_pid=loc_public_martigny.pid
            )
        )
        assert res.status_code == 200
        actions = data['action_applied']
        onloan_item = Item.get_record_by_pid(data['metadata']['pid'])
        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

        loan_end_date = ciso8601.parse_datetime(loan.get('end_date'))
        loan_end_date_formatted = loan_end_date.strftime('%Y-%m-%d')
        transaction_date_formatted = transaction_date.strftime('%Y-%m-%d')
        assert loan_end_date_formatted == transaction_date_formatted