Exemple #1
0
def test_loan_return_receiver(app, db, access_token):
    """Use the webhooks api to loan and return an item."""
    item_uuid = uuid.uuid4()
    item_data = {}
    pid = circulation_item_minter(item_uuid, item_data)
    item = Item.create(item_data, id_=item_uuid)
    with app.test_request_context():
        with app.test_client() as client:
            url = url_for('invenio_webhooks.event_list',
                          receiver_id='circulation_loan')
            url += '?access_token=' + access_token
            data = {'item_id': pid.pid_value}
            res = client.post(url, data=json.dumps(data),
                              content_type='application/json')

            assert res.status_code == 202

            item = Item.get_record(item.id)
            assert item['_circulation']['status'] == ItemStatus.ON_LOAN
            assert len(item['_circulation']['holdings']) == 1

            url = url_for('invenio_webhooks.event_list',
                          receiver_id='circulation_return')
            url += '?access_token=' + access_token
            data = {'item_id': pid.pid_value}
            res = client.post(url, data=json.dumps(data),
                              content_type='application/json')

            assert res.status_code == 202

            item = Item.get_record(item.id)
            assert item['_circulation']['status'] == ItemStatus.ON_SHELF
            assert len(item['_circulation']['holdings']) == 0
Exemple #2
0
def test_extend_receiver(app, db, access_token):
    """Use the webhooks api to an item loan."""
    item_uuid = uuid.uuid4()
    item_data = {}
    pid = circulation_item_minter(item_uuid, item_data)
    item = Item.create(item_data, id_=item_uuid)
    with app.test_request_context():
        with app.test_client() as client:
            url = url_for('invenio_webhooks.event_list',
                          receiver_id='circulation_loan')
            url += '?access_token=' + access_token
            data = {'item_id': pid.pid_value}
            res = client.post(url, data=json.dumps(data),
                              content_type='application/json')

            assert res.status_code == 202

            item = Item.get_record(item.id)
            assert item['_circulation']['status'] == ItemStatus.ON_LOAN

            url = url_for('invenio_webhooks.event_list',
                          receiver_id='circulation_extend')
            url += '?access_token=' + access_token
            data = {
                'item_id': pid.pid_value,
                'requested_end_date': datetime.date.today().isoformat(),
            }
            res = client.post(url, data=json.dumps(data),
                              content_type='application/json')

            assert res.status_code == 202

            item = Item.get_record(item.id)
            assert item['_circulation']['status'] == ItemStatus.ON_LOAN
Exemple #3
0
def test_dry_run(app, db, access_token):
    """Use the webhooks api to loan and return an item."""
    item_uuid = uuid.uuid4()
    item_data = {}
    pid = circulation_item_minter(item_uuid, item_data)
    item = Item.create(item_data, id_=item_uuid)
    with app.test_request_context():
        with app.test_client() as client:
            # Successful request
            url = url_for('invenio_webhooks.event_list',
                          receiver_id='circulation_loan')
            url += '?access_token=' + access_token
            data = {
                'item_id': pid.pid_value,
                'dry_run': True,
            }
            res = client.post(url, data=json.dumps(data),
                              content_type='application/json')

            assert res.status_code == 204

            item = Item.get_record(item.id)
            assert item['_circulation']['status'] == ItemStatus.ON_SHELF
            assert len(item['_circulation']['holdings']) == 0

            # Invalid request
            url = url_for('invenio_webhooks.event_list',
                          receiver_id='circulation_loan')
            url += '?access_token=' + access_token
            yesterday = datetime.date.today() + datetime.timedelta(days=-1)
            data = {
                'item_id': pid.pid_value,
                'start_date': str(yesterday),
                'dry_run': True,
            }
            res = client.post(url, data=json.dumps(data),
                              content_type='application/json')

            assert res.status_code == 400