def pds_label():
    return PVLModule({
        '^IMAGE': ('5600R.IMG', 12),
        'SPACECRAFT_NAME': 'TEST CRAFT',
        'INSTRUMENT_NAME': 'TEST INSTRUMENT',
        'TARGET_NAME': 'TEST TARGET'
    })
def test_bad_spacecraftname_instrument_insert(session, session_maker):
    instrument_id = get_instrument_id(
        PVLModule({'INSTRUMENT_NAME': 'TEST INSTRUMENT'}), session_maker)
    assert instrument_id == None
    with pytest.raises(sqlalchemy.orm.exc.NoResultFound):
        session.query(models.Instruments).filter(
            models.Instruments.instrumentid == instrument_id).one()
def test_datafiles_insert(mocked_pds_id, mocked_isis_id, session,
                          session_maker, pds_label):
    pds_label = PVLModule({
        '^IMAGE': ('5600R.IMG', 12),
        'SPACECRAFT_NAME': 'TEST CRAFT',
        'INSTRUMENT_NAME': 'TEST INSTRUMENT',
        'TARGET_NAME': 'TEST TARGET'
    })
    input_cube = '/Path/to/my/cube.cub'
    upc_id = create_datafiles_record(pds_label,
                                     '/Path/to/label/location/label.lbl',
                                     '/Path/to/my/cube.cub', session_maker)
    mocked_isis_id.assert_called_with(input_cube)
    mocked_pds_id.assert_called_with(input_cube)

    resp = session.query(models.DataFiles).filter(
        models.DataFiles.isisid == 'ISISSERIAL').first()
    assert upc_id == resp.upcid
def test_bad_spacecraft_name():
    spacecraft_name = get_spacecraft_name(PVLModule())
    assert spacecraft_name == None
def test_bad_instrument_name():
    instrument_name = get_instrument_name(PVLModule())
    assert instrument_name == None
def test_bad_target_name():
    target_name = get_target_name(PVLModule())
    assert target_name == None
def test_bad_instrumentname_instrument_insert(session, session_maker):
    instrument_id = get_instrument_id(PVLModule(), session_maker)
    assert instrument_id == None
    with pytest.raises(sqlalchemy.orm.exc.NoResultFound):
        session.query(models.Instruments).filter(
            models.Instruments.instrumentid == instrument_id).one()
def test_bad_target_insert(session, session_maker):
    target_id = get_target_id(PVLModule(), session_maker)
    assert target_id == None
    with pytest.raises(sqlalchemy.orm.exc.NoResultFound):
        session.query(
            models.Targets).filter(models.Targets.targetid == target_id).one()