Beispiel #1
0
def populate_from_data(objects):
    """Push the given list of photo dictionaries into the database."""
    database_url = os.environ.get("MARS_DATABASE_URL", None)
    engine = create_engine(database_url)
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        DBSession.add_all(objects)
        DBSession.flush()
def populate_from_data(objects):
    """Push the given list of photo dictionaries into the database."""
    database_url = os.environ.get("MARS_DATABASE_URL", None)
    engine = create_engine(database_url)
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        DBSession.add_all(objects)
        DBSession.flush()
Beispiel #3
0
def sqlengine(request):
    """Return sql engine."""
    engine = create_engine(TEST_DATABASE_URL)
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)

    def teardown():
        Base.metadata.drop_all(engine)

    request.addfinalizer(teardown)
    return engine
Beispiel #4
0
def dbtransaction(request, sqlengine):
    """Create database transaction connection."""
    connection = sqlengine.connect()
    transaction = connection.begin()
    DBSession.configure(bind=connection)

    def teardown():
        transaction.rollback()
        connection.close()
        DBSession.remove()

    request.addfinalizer(teardown)
    return connection
Beispiel #5
0
def pre_pop_transaction(request, sqlengine):
    """Create database transaction connection."""
    from mars_street_view.models import init_rovers_and_cameras
    from mars_street_view.api_call import load_full_sample_data
    connection = sqlengine.connect()
    transaction = connection.begin()
    DBSession.configure(bind=connection)
    init_rovers_and_cameras()

    rov_cam_data = init_rovers_and_cameras()
    DBSession.add_all(rov_cam_data)
    sample_data = load_full_sample_data()
    DBSession.add_all([Photo(**result) for result in sample_data])
    DBSession.flush()

    def teardown():
        transaction.rollback()
        connection.close()
        DBSession.remove()

    request.addfinalizer(teardown)
    return connection