Пример #1
0
def test_save_patron(get_uuid_pid_by_email, reindex, record_indexer, url_for1,
                     url_for2, send_email, confirm_user, app, db,
                     minimal_patron_only_record):
    """Test save patron"""

    # Convenient references
    security = LocalProxy(lambda: app.extensions['security'])
    datastore = LocalProxy(lambda: security.datastore)
    datastore.create_role(name='patrons')

    # hack the return value
    get_uuid_pid_by_email.return_value = None, None

    email = '*****@*****.**'
    u1 = datastore.create_user(email=email,
                               active=False,
                               password=hash_password('aafaf4as5fa'))
    datastore.commit()
    u2 = datastore.find_user(email=email)
    assert u1 == u2
    assert 1 == User.query.filter_by(email=email).count()
    email = minimal_patron_only_record.get('email')
    assert datastore.get_user(email) is None

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

    # Verify that user exists in app's datastore
    user_ds = datastore.get_user(email)
    assert user_ds
    assert user_ds.email == email
Пример #2
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