def test_environmental(jail_environ): os.environ['ENG_BASE_URL'] = ALTERNATE_URL try: engdb = engdb_tools.ENGDB_Service() except Exception: pytest.skip('Alternate engineering db not available for test.') assert engdb.base_url == ALTERNATE_URL
def engdb(scope='module'): """ Ensure the live engineering RESTful service is available """ try: engdb = engdb_tools.ENGDB_Service() except Exception: pytest.skip('ENGDB service is not accessible.') else: return engdb
def test_environmental_bad(jail_environ): alternate = 'http://google.com/' did_except = False os.environ['ENG_BASE_URL'] = alternate try: engdb = engdb_tools.ENGDB_Service() except Exception: did_except = True assert did_except, 'DB connection falsely created for {}'.format( engdb.base_url)
def test_environmetal(): old = os.environ.get('ENG_BASE_URL', None) try: os.environ['ENG_BASE_URL'] = ALTERNATE_URL engdb = engdb_tools.ENGDB_Service() except Exception: pytest.skip('Alternate engineering db not available for test.') finally: if old is None: del os.environ['ENG_BASE_URL'] else: os.environ['ENG_BASE_URL'] = old assert engdb.base_url == ALTERNATE_URL
def engdb(jail_environ): """ Ensure the live engineering RESTful service is available """ try: del os.environ['MAST_API_TOKEN'] except KeyError: pass try: engdb = engdb_tools.ENGDB_Service() except Exception as exception: pytest.skip(f'ENGDB service is not accessible: {exception}') else: return engdb
def test_environmetal_bad(): alternate = 'http://google.com/' old = os.environ.get('ENG_BASE_URL', None) did_except = False try: os.environ['ENG_BASE_URL'] = alternate engdb = engdb_tools.ENGDB_Service() except Exception: did_except = True finally: if old is None: del os.environ['ENG_BASE_URL'] else: os.environ['ENG_BASE_URL'] = old assert did_except, 'DB connection falsely created for {}'.format( engdb.base_url)
def cache_engdb(mnemonics=MNEMONICS_TO_CACHE, starttime='2016-01-18T15:40:00', endtime='2016-01-18T15:40:05', db_path=ENGDB_PATH): """Create a local cache of the database Parameters ---------- mnemonics: iterable List of mnemonics to retrieve starttime: str or astropy.time.Time The, inclusive, start time to retireve from. endttime: str or astropy.time.Time The, inclusive, end time to retireve from. path: str Path of the cache directory. Notes ----- Suggested shell command is `python -c 'from jwst.lib.tests.engdb_mock import cache_engdb; cache_engdb()'` """ if not os.path.exists(db_path): os.mkdir(db_path) edb = engdb_tools.ENGDB_Service() # Get the meta info for all mnemonics regardless. meta = edb.get_meta() with open(os.path.join(db_path, META), 'w') as fp: json.dump(meta, fp) for mnemonic in mnemonics: records = edb.get_records(mnemonic, starttime, endtime) # Remove the request times. These are filled back in # during retrieval. del records['ReqSTime'] del records['ReqETime'] with open(os.path.join(db_path, mnemonic_data_fname(mnemonic)), 'w') as fp: json.dump(records, fp)
def eng_db(): with requests_mock.Mocker() as rm: # Define response for aliveness url = ''.join([ engdb_tools.ENGDB_BASE_URL, engdb_tools.ENGDB_METADATA ]) rm.get(url, text='Success') # Define good responses good_responses = register_responses( rm, mock_db[1:2], STARTTIME, ENDTIME ) # Define with zeros in the first row zero_responses = register_responses( rm, mock_db, ZEROTIME_START, ENDTIME ) edb = engdb_tools.ENGDB_Service() # Test for good responses. for mnemonic in mock_db.colnames: r = edb.get_records(mnemonic, STARTTIME, ENDTIME) assert r == good_responses[mnemonic] # Test for zeros. for mnemonic in mock_db.colnames: r = edb.get_records(mnemonic, ZEROTIME_START, ENDTIME) assert r == zero_responses[mnemonic] yield edb
def engdb(): """Setup the service to operate through the mock service""" with EngDB_Mocker(): yield engdb_tools.ENGDB_Service()
def eng_db_jw703(): """Setup the test engineering database""" with EngDB_Mocker(db_path=db_jw703_path): engdb = engdb_tools.ENGDB_Service() yield engdb
def test_bad_server(): with pytest.raises(Exception): engdb_tools.ENGDB_Service(BAD_SERVER)
def engdb(): """Setup the mock engineering database""" db_path = Path(__file__).parents[1] / 'lib' / 'tests' / 'data' / 'engdb' with EngDB_Mocker(db_path=db_path): engdb = engdb_tools.ENGDB_Service(base_url='http://localhost') yield engdb
def engdb_service(): """Setup the service to operate through the mock service""" with EngDB_Mocker(): yield engdb_tools.ENGDB_Service(base_url='http://localhost')
def eng_db_ngas(): """Setup the test engineering database""" with EngDB_Mocker(db_path=db_ngas_path): engdb = engdb_tools.ENGDB_Service(base_url='http://localhost') yield engdb