Esempio n. 1
0
def observation_portal_side_effect(*args, **kwargs):
    site = kwargs['params']['site']
    start = datetime.strftime(
        parse(kwargs['params']['start_after']).replace(tzinfo=None).date(),
        '%Y%m%d')
    filename = 'test_obs_portal_response_{site}_{start}.json'.format(
        site=site, start=start)
    filename = get_pkg_data_filename(
        'data/{filename}'.format(filename=filename), TEST_PACKAGE)
    return FakeResponse(filename)
Esempio n. 2
0
import os

import mock

from banzai import dbs
from banzai.tests.utils import FakeResponse
from astropy.utils.data import get_pkg_data_filename


@mock.patch('banzai.dbs.requests.get',
            return_value=FakeResponse(
                get_pkg_data_filename('data/configdb_example.json',
                                      'banzai.tests')))
def setup_module(mockrequests):
    dbs.create_db('.', db_address='sqlite:///test.db')


def teardown_module():
    os.remove('test.db')


def test_add_or_update():
    with dbs.get_session(db_address='sqlite:///test.db') as db_session:
        # Add a fake telescope
        dbs.add_or_update_record(
            db_session, dbs.Instrument, {
                'site': 'bpl',
                'camera': 'kb101',
                'enclosure': 'doma',
                'telescope': '1m0a'
            }, {
Esempio n. 3
0
def observation_portal_side_effect(*args, **kwargs):
    site = kwargs['params']['site']
    start = datetime.strftime(parse(kwargs['params']['start_after']).replace(tzinfo=None).date(), '%Y%m%d')
    filename = 'test_obs_portal_response_{site}_{start}.json'.format(site=site, start=start)
    filename = pkg_resources.resource_filename('banzai_nres.tests', f'data/{filename}')
    return FakeResponse(filename)
Esempio n. 4
0
def observation_portal_side_effect(*args, **kwargs):
    site = kwargs['params']['site']
    start = datetime.strftime(
        parse(kwargs['params']['start_after']).replace(tzinfo=None).date(),
        '%Y%m%d')
    filename = 'test_obs_portal_response_{site}_{start}.json'.format(
        site=site, start=start)
    filename = get_pkg_data_filename(
        'data/{filename}'.format(filename=filename), TEST_PACKAGE)
    return FakeResponse(filename)


@pytest.mark.e2e
@pytest.fixture(scope='module')
@mock.patch('banzai.dbs.requests.get',
            return_value=FakeResponse(CONFIGDB_FILENAME))
def init(configdb):
    create_db('.',
              db_address=os.environ['DB_ADDRESS'],
              configdb_address='http://configdbdev.lco.gtn/sites/')
    for instrument in INSTRUMENTS:
        populate_calibration_table_with_bpms(
            os.path.join(DATA_ROOT, instrument, 'bpm'),
            db_address=os.environ['DB_ADDRESS'])


@pytest.mark.e2e
@pytest.mark.master_bias
class TestMasterBiasCreation:
    @pytest.fixture(autouse=True)
    @mock.patch('banzai.utils.observation_utils.requests.get',
Esempio n. 5
0

def mock_phoenix_models_in_db(db_address):
    with open(PHOENIX_FILENAME) as f:
        phoenix_data = json.load(f)
    with dbs.get_session(db_address) as db_session:
        db_session.bulk_insert_mappings(banzai_nres.dbs.PhoenixModel, phoenix_data)
        dbs.add_or_update_record(db_session, banzai_nres.dbs.ResourceFile, {'key': 'phoenix_wavelengths'},
                                 {'filename': 'phoenix_wavelength.fits',
                                  'location': 's3://banzai-nres-phoenix-models-lco-global',
                                  'key': 'phoenix_wavelengths'})


@pytest.mark.e2e
@pytest.fixture(scope='module')
@mock.patch('banzai.dbs.requests.get', return_value=FakeResponse(CONFIGDB_FILENAME))
def init(configdb):
    os.system(f'banzai_nres_create_db --db-address={os.environ["DB_ADDRESS"]}')
    dbs.populate_instrument_tables(db_address=os.environ["DB_ADDRESS"], configdb_address='http://fakeconfigdb')
    os.system((f'banzai_add_site --site elp --latitude 30.67986944 --longitude -104.015175'
              f' --elevation 2027 --timezone -6 --db-address={os.environ["DB_ADDRESS"]}'))
    os.system((f'banzai_add_site --site lsc --latitude -30.1673833333 --longitude -70.8047888889'
              f' --elevation 2198 --timezone -4 --db-address={os.environ["DB_ADDRESS"]}'))
    os.system((f'banzai_add_instrument --site lsc --camera fl09 --name nres01'
              f' --instrument-type 1m0-NRES-SciCam --db-address={os.environ["DB_ADDRESS"]}'))
    os.system((f'banzai_add_instrument --site elp --camera fl17 --name nres02'
              f' --instrument-type 1m0-NRES-SciCam --db-address={os.environ["DB_ADDRESS"]}'))

    mock_phoenix_models_in_db(os.environ["DB_ADDRESS"])
    for instrument in INSTRUMENTS:
        for bpm_filename in glob(os.path.join(DATA_ROOT, instrument, 'bpm/*bpm*')):