def test_rest_explicit_loan_valid_action(
    app, json_headers, params, mock_is_item_available_for_checkout,
    loan_created
):
    """Test API valid action on loan."""
    loan_pid = loan_pid_fetcher(loan_created.id, loan_created)

    res, payload = _post(app, json_headers, params,
                         pid_value=loan_pid.pid_value, action='checkout')
    assert res.status_code == 202
    assert payload['metadata']['state'] == 'ITEM_ON_LOAN'
예제 #2
0
def test_rest_explicit_loan_valid_action(app, json_headers, params,
                                         loan_created):
    """Test API valid action on loan."""
    loan_pid = loan_pid_fetcher(loan_created.id, loan_created)

    res, payload = _post(app,
                         json_headers,
                         params,
                         pid_value=loan_pid.pid_value,
                         action='checkout')
    assert res.status_code == 202
    assert payload['metadata']['state'] == 'ITEM_ON_LOAN'
def test_rest_explicit_loan_valid_action(app, json_headers, params,
                                         mock_is_item_available, loan_created):
    """Test API valid action on loan."""
    loan_pid = loan_pid_fetcher(loan_created.id, loan_created)

    res, payload = _post(app,
                         json_headers,
                         params,
                         pid_value=loan_pid.pid_value,
                         action='checkout')
    assert res.status_code == HTTP_CODES['accepted']
    assert payload['metadata']['state'] == 'ITEM_ON_LOAN'
예제 #4
0
def test_loans_create(db, loan_data_tmp):
    """Test loananisation creation."""
    loan = Loan.create(loan_data_tmp, delete_pid=True)
    assert loan == loan_data_tmp
    assert loan.get('loan_pid') == '1'
    assert loan.get('state') == 'ITEM_ON_LOAN'

    loan = Loan.get_record_by_pid('1')
    assert loan == loan_data_tmp

    fetched_pid = loan_pid_fetcher(loan.id, loan)
    assert fetched_pid.pid_value == '1'
def test_persist_loan_parameters(loan_created, db, params,
                                 mock_is_item_available):
    """Test that input params are correctly persisted."""
    loan_pid = loan_pid_fetcher(loan_created.id, loan_created)
    loan = current_circulation.circulation.trigger(
        loan_created, **dict(params, trigger="checkout"))
    db.session.commit()

    params["loan_pid"] = loan_pid.pid_value
    params["state"] = "ITEM_ON_LOAN"
    params["start_date"] = loan["start_date"]
    params["end_date"] = loan["end_date"]
    params["trigger"] = loan["trigger"]
    params["$schema"] = "https://localhost:5000/schema/loans/loan-v1.0.0.json"
    assert loan == params
예제 #6
0
def test_rest_loan_invalid_action(app, json_headers, params, loan_created):
    """Test API invalid action on loan."""
    loan = current_circulation.circulation.trigger(
        loan_created,
        **dict(params,
               trigger='request',
               pickup_location_pid='pickup_location_pid'))
    assert loan['state'] == 'PENDING'

    loan_pid = loan_pid_fetcher(loan.id, loan)

    res, payload = _post(app,
                         json_headers,
                         params,
                         pid_value=loan_pid.pid_value,
                         action='extend')
    assert res.status_code == 400
    assert 'message' in payload
def test_persist_loan_parameters(
    loan_created, db, params, mock_is_item_available_for_checkout
):
    """Test that input params are correctly persisted."""
    loan_pid = loan_pid_fetcher(loan_created.id, loan_created)
    loan = current_circulation.circulation.trigger(
        loan_created, **dict(params, trigger="checkout")
    )
    db.session.commit()

    params["loan_pid"] = loan_pid.pid_value
    params["state"] = "ITEM_ON_LOAN"
    params["start_date"] = loan["start_date"]
    params["end_date"] = loan["end_date"]
    params["trigger"] = loan["trigger"]
    params["item"] = {"ref": "6"}
    params["$schema"] = "https://localhost:5000/schema/loans/loan-v1.0.0.json"
    assert loan == params
예제 #8
0
def test_rest_get_loan(app, json_headers, loan_created):
    """Test API GET call to fetch a loan by PID."""
    loan_pid = loan_pid_fetcher(loan_created.id, loan_created)
    expected_links = {
        'actions': {
            'request': build_url_action_for_pid(loan_pid, 'request'),
            'checkout': build_url_action_for_pid(loan_pid, 'checkout')
        }
    }

    with app.test_client() as client:
        url = url_for('invenio_records_rest.loanid_item',
                      pid_value=loan_pid.pid_value)
        res = client.get(url, headers=json_headers)

    assert res.status_code == 200
    loan_dict = json.loads(res.data.decode('utf-8'))
    assert loan_dict['metadata']['state'] == loan_created['state']
    assert loan_dict['links'] == expected_links
def test_rest_loan_invalid_action(
    app, json_headers, params, mock_is_item_available_for_checkout,
    loan_created
):
    """Test API invalid action on loan."""
    loan = current_circulation.circulation.trigger(
        loan_created,
        **dict(params, trigger='request',
               pickup_location_pid='pickup_location_pid')
    )
    db.session.commit()
    assert loan['state'] == 'PENDING'

    loan_pid = loan_pid_fetcher(loan.id, loan)

    res, payload = _post(app, json_headers, params,
                         pid_value=loan_pid.pid_value, action='extend')
    assert res.status_code == 400
    assert 'message' in payload
def test_rest_get_loan(app, json_headers, loan_created):
    """Test API GET call to fetch a loan by PID."""
    loan_pid = loan_pid_fetcher(loan_created.id, loan_created)
    expected_links = {
        'actions': {
            'request': build_url_action_for_pid(loan_pid, 'request'),
            'checkout': build_url_action_for_pid(loan_pid, 'checkout')
        }
    }

    with app.test_client() as client:
        url = url_for('invenio_records_rest.loanid_item',
                      pid_value=loan_pid.pid_value)
        res = client.get(url, headers=json_headers)

    assert res.status_code == 200
    loan_dict = json.loads(res.data.decode('utf-8'))
    assert loan_dict['metadata']['state'] == loan_created['state']
    assert loan_dict['links'] == expected_links
def test_persist_loan_parameters(loan_created, db, params,
                                 mock_ensure_item_is_available_for_checkout):
    """Test that input params are correctly persisted."""
    mock_ensure_item_is_available_for_checkout.side_effect = None

    loan_pid = loan_pid_fetcher(loan_created.id, loan_created)
    with SwappedConfig("CIRCULATION_ITEM_LOCATION_RETRIEVER",
                       lambda x: "pickup_location_pid"):
        loan = current_circulation.circulation.trigger(
            loan_created, **dict(params, trigger="checkout"))
    db.session.commit()

    params["pid"] = loan_pid.pid_value
    params["state"] = "ITEM_ON_LOAN"
    params["start_date"] = loan["start_date"]
    params["end_date"] = loan["end_date"]
    params["trigger"] = loan["trigger"]
    params["pickup_location_pid"] = loan["pickup_location_pid"]
    params["item"] = {"ref": "6"}
    params["$schema"] = "https://localhost:5000/schema/loans/loan-v1.0.0.json"
    assert loan == params
def test_rest_loan_invalid_action(app, json_headers, params,
                                  mock_is_item_available, loan_created,
                                  mock_can_be_requested):
    """Test API invalid action on loan."""
    loan = current_circulation.circulation.trigger(
        loan_created,
        **dict(params,
               trigger='request',
               pickup_location_pid='pickup_location_pid'))
    db.session.commit()
    assert loan['state'] == 'PENDING'

    loan_pid = loan_pid_fetcher(loan.id, loan)

    res, payload = _post(app,
                         json_headers,
                         params,
                         pid_value=loan_pid.pid_value,
                         action='extend')
    assert res.status_code == HTTP_CODES['bad_request']
    assert 'message' in payload
예제 #13
0
def test_rest_automatic_loan_valid_action(app, json_headers, params,
                                          loan_created):
    """Test API valid action on loan."""
    loan = current_circulation.circulation.trigger(
        loan_created,
        **dict(params,
               trigger='request',
               pickup_location_pid='pickup_location_pid'))
    assert loan['state'] == 'PENDING'

    app.config[
        'CIRCULATION_ITEM_LOCATION_RETRIEVER'] = lambda x: 'pickup_location_pid'

    loan_pid = loan_pid_fetcher(loan.id, loan)

    res, payload = _post(app,
                         json_headers,
                         params,
                         pid_value=loan_pid.pid_value,
                         action='next')
    assert res.status_code == 202
    assert payload['metadata']['state'] == 'ITEM_AT_DESK'
def test_rest_automatic_loan_valid_action(
    app, json_headers, params, loan_created
):
    """Test API valid action on loan."""
    loan = current_circulation.circulation.trigger(
        loan_created,
        **dict(params, trigger='request',
               pickup_location_pid='pickup_location_pid')
    )
    db.session.commit()
    assert loan['state'] == 'PENDING'

    app.config[
        'CIRCULATION_ITEM_LOCATION_RETRIEVER'
    ] = lambda x: 'pickup_location_pid'

    loan_pid = loan_pid_fetcher(loan.id, loan)

    res, payload = _post(app, json_headers, params,
                         pid_value=loan_pid.pid_value, action='next')
    assert res.status_code == 202
    assert payload['metadata']['state'] == 'ITEM_AT_DESK'