Esempio n. 1
0
def test_patron(reindex, get_borrowed_documents_pids, get_uuid_pid_by_email,
                record_indexer, url_for1, url_for2, send_email, confirm_user,
                app, db, minimal_patron_record, minimal_document_record,
                minimal_item_record):
    """Test patron"""

    # Convenient references
    security = LocalProxy(lambda: app.extensions['security'])
    datastore = LocalProxy(lambda: security.datastore)
    # hack the return value
    get_uuid_pid_by_email.return_value = None, None

    next, pid = save_patron(minimal_patron_record, Patron.provider.pid_type,
                            Patron.fetcher, Patron.minter, record_indexer,
                            Patron, None)
    email = minimal_patron_record.get('email')

    # Verify that user exists in app's datastore
    user = datastore.get_user(email)
    assert user

    # hack the return value
    get_uuid_pid_by_email.return_value = pid.object_uuid, pid.id
    patron = Patron.get_patron_by_email(email)
    assert patron.get('email') == email

    patron = Patron.get_patron_by_user(user)
    assert patron.get('email') == email

    doc = DocumentsWithItems.create(minimal_document_record, dbcommit=True)

    # hack the return value
    get_borrowed_documents_pids.return_value = [doc.pid]
    docs = patron.get_borrowed_documents()
    assert docs[0] == doc
Esempio n. 2
0
def test_delete_item(reindex, db,
                     minimal_document_record, minimal_item_record):
    """Test DocumentWithItems item deletion."""
    doc = DocumentsWithItems.create(minimal_document_record)
    item = Item.create(minimal_item_record)
    doc.add_item(item)
    doc.dbcommit()
    pid = item.persistent_identifier
    assert pid.is_registered()
    doc.remove_item(item, force=True)
    doc.dbcommit()
    assert True
    assert pid.is_deleted()
    assert doc.itemslist == []

    item1 = Item.create(minimal_item_record)
    doc.add_item(item1)
    item2 = Item.create(minimal_item_record)
    doc.add_item(item2)
    item3 = Item.create(minimal_item_record)
    doc.add_item(item3)
    doc.dbcommit()
    doc.remove_item(item2, force=True)
    doc.dbcommit()
    assert len(doc.itemslist) == 2
    assert doc.itemslist[0]['pid'] == '2'
    assert doc.itemslist[1]['pid'] == '4'
Esempio n. 3
0
def test_delete_document(reindex, db,
                         minimal_document_record, minimal_item_record):
    """Test DocumentWithItems deletion."""
    doc = DocumentsWithItems.create(minimal_document_record)
    item1 = Item.create(minimal_item_record, dbcommit=True)
    pid1 = item1.persistent_identifier
    doc.add_item(item1)
    item2 = Item.create(minimal_item_record, dbcommit=True)
    pid2 = item2.persistent_identifier
    doc.add_item(item2)
    item3 = Item.create(minimal_item_record, dbcommit=True)
    pid3 = item3.persistent_identifier
    doc.add_item(item3)
    doc.dbcommit()
    assert DocumentsItemsMetadata.query.count() == 3
    assert RecordMetadata.query.count() == 4
    assert pid1.is_registered()
    assert pid2.is_registered()
    assert pid3.is_registered()
    doc.delete(force=True)
    assert DocumentsItemsMetadata.query.count() == 0
    assert RecordMetadata.query.count() == 0
    assert pid1.is_deleted()
    assert pid2.is_deleted()
    assert pid3.is_deleted()
Esempio n. 4
0
def create_minimal_resources_on_loan(db, minimal_member_record,
                                     minimal_location_record,
                                     item_record_on_loan, minimal_book_record):
    """Simple patron record."""
    member = MemberWithLocations.create(minimal_member_record, dbcommit=True)
    location = Location.create(minimal_location_record, dbcommit=True)
    member.add_location(location)
    doc = DocumentsWithItems.create(minimal_book_record, dbcommit=True)
    item = Item.create({})
    item.update(item_record_on_loan, dbcommit=True)
    doc.add_item(item, dbcommit=True)
    db.session.commit()
    yield doc, item, member, location
Esempio n. 5
0
def test_create(db, minimal_document_record, minimal_item_record,
                minimal_member_record, minimal_location_record):
    """Test DocumentWithItems creation."""
    memb = MemberWithLocations.create(minimal_member_record, dbcommit=True)
    loc = Location.create(minimal_location_record, dbcommit=True)
    memb.add_location(loc, dbcommit=True)
    minimal_item_record['location_pid'] = loc.pid
    item = Item.create(minimal_item_record, dbcommit=True)
    doc = DocumentsWithItems.create(minimal_document_record, dbcommit=True)
    assert doc.itemslist == []

    doc.add_item(item, dbcommit=True)
    assert doc.itemslist[0] == item

    dump = doc.dumps()
    assert dump['itemslist'][0] == item.dumps()