def check_this_api(out_dir, colors, api, mod): if hasattr(mod, 'api_server_check'): label = "Data source '%s'" % api status = 'down' if isAPIconnected(src=api, data=1): status = 'up' # Create json file with full results for badge: color = colors[status] message = status data = {} data['schemaVersion'] = 1 data['label'] = label data['message'] = message data['color'] = color outfile = os.path.join(out_dir, 'argopy_api_status_%s.json' % api) with open(outfile, 'w') as f: json.dump(data, f) # Create text file with status: outfile = os.path.join(out_dir, '%s.txt' % api.upper()) with open(outfile, 'w') as f: f.write(status.upper())
def test_isAPIconnected(): assert isinstance(isAPIconnected(src="erddap", data=True), bool) assert isinstance(isAPIconnected(src="erddap", data=False), bool)
from argopy import DataFetcher as ArgoDataFetcher from argopy.errors import InvalidFetcherAccessPoint, InvalidFetcher, ErddapServerError, \ CacheFileNotFound, FileSystemHasNoCache, FtpPathError from argopy.utilities import list_available_data_src, isconnected, isAPIconnected, erddap_ds_exists AVAILABLE_SOURCES = list_available_data_src() CONNECTED = isconnected() CONNECTEDAPI = {src: False for src in AVAILABLE_SOURCES.keys()} if CONNECTED: DSEXISTS = erddap_ds_exists(ds="ArgoFloats") DSEXISTS_bgc = erddap_ds_exists(ds="ArgoFloats-bio") DSEXISTS_ref = erddap_ds_exists(ds="ArgoFloats-ref") for src in AVAILABLE_SOURCES.keys(): try: CONNECTEDAPI[src] = isAPIconnected(src=src, data=True) except InvalidFetcher: pass else: DSEXISTS = False DSEXISTS_bgc = False DSEXISTS_ref = False # List tests: def test_invalid_accesspoint(): src = list(AVAILABLE_SOURCES.keys())[0] # Use the first valid data source with pytest.raises(InvalidFetcherAccessPoint): ArgoDataFetcher(src=src).invalid_accesspoint.to_xarray( ) # Can't get data if access point not defined first
import argopy from argopy import IndexFetcher as ArgoIndexFetcher from argopy.errors import InvalidFetcherAccessPoint, InvalidFetcher, \ FileSystemHasNoCache, CacheFileNotFound, ErddapServerError, DataNotFound from argopy.utilities import list_available_index_src, isconnected, isAPIconnected, erddap_ds_exists AVAILABLE_INDEX_SOURCES = list_available_index_src() CONNECTED = isconnected() CONNECTEDAPI = {src: False for src in AVAILABLE_INDEX_SOURCES.keys()} if CONNECTED: DSEXISTS = erddap_ds_exists(ds="ArgoFloats-index") for src in AVAILABLE_INDEX_SOURCES.keys(): try: CONNECTEDAPI[src] = isAPIconnected(src=src, data=False) except InvalidFetcher: pass else: DSEXISTS = False def test_invalid_accesspoint(): src = list( AVAILABLE_INDEX_SOURCES.keys())[0] # Use the first valid data source with pytest.raises(InvalidFetcherAccessPoint): ArgoIndexFetcher(src=src).invalid_accesspoint.to_xarray( ) # Can't get data if access point not defined first with pytest.raises(InvalidFetcherAccessPoint): ArgoIndexFetcher(src=src).to_xarray( ) # Can't get data if access point not defined first