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()
def test_full_params(dbtransaction, full_photo_params):
    """Test that a full set of params from NASA API will construct models."""
    rover = Rover(**full_photo_params['rover'])
    camera = Camera(**full_photo_params['camera'])
    # cam_short_name = full_photo_params['camera']['name']
    # camera_name = '_'.join((rover_name, cam_short_name))
    photo = Photo(**full_photo_params)
    DBSession.add_all([rover, camera, photo])
    DBSession.flush()
    assert photo.rover_name == rover.name and photo.camera_name == camera.name
Beispiel #4
0
def test_full_params(dbtransaction, full_photo_params):
    """Test that a full set of params from NASA API will construct models."""
    rover = Rover(**full_photo_params['rover'])
    camera = Camera(**full_photo_params['camera'])
    # cam_short_name = full_photo_params['camera']['name']
    # camera_name = '_'.join((rover_name, cam_short_name))
    photo = Photo(**full_photo_params)
    DBSession.add_all([rover, camera, photo])
    DBSession.flush()
    assert photo.rover_name == rover.name and photo.camera_name == camera.name
def test_photo_camera_relationship(dbtransaction, rover_params, camera_params, photo_params):
    """Test that Photo can access Camera's attributes through relationship."""
    rover = Rover(**rover_params)
    camera_params['rover_name'] = rover.name
    camera_params['rover_name'] = rover.name
    camera = Camera(**camera_params)
    photo_params['camera_name'] = camera.name
    photo = Photo(**photo_params)
    DBSession.add_all([rover, camera, photo])
    DBSession.flush()
    assert all([getattr(camera, attr) == getattr(photo.camera, attr)
                for attr in camera_params])
def test_photo_rover_relationship(dbtransaction, rover_params, camera_params,
                                  photo_params):
    """Test Rover, Photo have correct relationship after initialization."""
    rover = Rover(**rover_params)
    camera_params['rover_name'] = rover.name
    camera_params['rover_name'] = rover.name
    camera = Camera(**camera_params)
    photo_params['camera_name'] = camera.name
    photo = Photo(**photo_params)
    DBSession.add_all([rover, camera, photo])
    DBSession.flush()
    assert photo.rover_name == rover.name
Beispiel #7
0
def test_photo_rover_relationship(dbtransaction, rover_params, camera_params,
                                  photo_params):
    """Test Rover, Photo have correct relationship after initialization."""
    rover = Rover(**rover_params)
    camera_params['rover_name'] = rover.name
    camera_params['rover_name'] = rover.name
    camera = Camera(**camera_params)
    photo_params['camera_name'] = camera.name
    photo = Photo(**photo_params)
    DBSession.add_all([rover, camera, photo])
    DBSession.flush()
    assert photo.rover_name == rover.name
Beispiel #8
0
def test_photo_camera_relationship(dbtransaction, rover_params, camera_params,
                                   photo_params):
    """Test that Photo can access Camera's attributes through relationship."""
    rover = Rover(**rover_params)
    camera_params['rover_name'] = rover.name
    camera_params['rover_name'] = rover.name
    camera = Camera(**camera_params)
    photo_params['camera_name'] = camera.name
    photo = Photo(**photo_params)
    DBSession.add_all([rover, camera, photo])
    DBSession.flush()
    assert all([
        getattr(camera, attr) == getattr(photo.camera, attr)
        for attr in camera_params
    ])
Beispiel #9
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