def test_sx_adaptor_nothing(): c = ConfigSettings('servicex', 'servicex') c.clear() x = ServiceXConfigAdaptor(c) with pytest.raises(ServiceXException): x.get_servicex_adaptor_config()
def test_sx_adaptor_settings_name_worng(caplog): from confuse import Configuration c = Configuration('bogus', 'bogus') c.clear() c['api_endpoints'] = [{ 'type': 'my-type', 'name': 'my-fork', 'endpoint': 'http://my-left-foot.com:5000', 'token': 'forkingshirtballs.thegoodplace.bortles' }] x = ServiceXConfigAdaptor(c) with pytest.raises(ServiceXException) as e: x.get_servicex_adaptor_config('my-type') assert 'Unable to find type my-type' in str(e)
def test_sx_adaptor_settings_name_not_type(caplog): from confuse import Configuration c = Configuration('bogus', 'bogus') c.clear() c['api_endpoints'] = [ { 'type': 'my-type1', 'name': 'my-fork1', 'endpoint': 'http://my-left-foot1.com:5000', 'token': 'forkingshirtballs.thegoodplace.bortles' }, { 'type': 'my-type2', 'name': 'my-type1', 'endpoint': 'http://my-left-foot2.com:5000', 'token': 'forkingshirtballs.thegoodplace.bortles' }, ] x = ServiceXConfigAdaptor(c) endpoint, token = x.get_servicex_adaptor_config('my-type1') assert endpoint == 'http://my-left-foot2.com:5000' assert token == 'forkingshirtballs.thegoodplace.bortles' assert len(caplog.record_tuples) == 0
def test_default_config_endpoint(): c = ConfigSettings('servicex', 'servicex') c.clear() c._add_default_source() x = ServiceXConfigAdaptor(c) end_point, token = x.get_servicex_adaptor_config() assert end_point == 'http://localhost:5000' assert token is None
def test_sx_adaptor_settings_backend_name_requested_with_unlabeled_type( caplog): 'Request None for a backend name' from confuse import Configuration c = Configuration('bogus', 'bogus') c.clear() c['api_endpoints'] = [{ 'endpoint': 'http://my-left-foot.com:5000', 'token': 'forkingshirtballs.thegoodplace.bortles' }] x = ServiceXConfigAdaptor(c) with pytest.raises(ServiceXException) as e: _ = x.get_servicex_adaptor_config('xaod') assert 'Unable to find' in str(e)
def test_sx_adaptor_settings_backend_name_unlabeled_type(): 'Request None for a backend name' from confuse import Configuration c = Configuration('bogus', 'bogus') c.clear() c['api_endpoints'] = [{ 'type': 'xaod', 'endpoint': 'http://my-left-foot.com:5000', 'token': 'forkingshirtballs.thegoodplace.bortles' }, { 'endpoint': 'http://my-left-foot.com:5001', 'token': 'forkingshirtballs.thegoodplace.bortles1' }] x = ServiceXConfigAdaptor(c) endpoint, token = x.get_servicex_adaptor_config() assert endpoint == 'http://my-left-foot.com:5001' assert token == 'forkingshirtballs.thegoodplace.bortles1'
def test_sx_adaptor_settings_backend_name_requested_with_unlabeled_type( caplog): 'Request None for a backend name' from confuse import Configuration c = Configuration('bogus', 'bogus') c.clear() c['api_endpoints'] = [{ 'endpoint': 'http://my-left-foot.com:5000', 'token': 'forkingshirtballs.thegoodplace.bortles' }] x = ServiceXConfigAdaptor(c) endpoint, token = x.get_servicex_adaptor_config('xaod') assert endpoint == 'http://my-left-foot.com:5000' assert token == 'forkingshirtballs.thegoodplace.bortles' assert caplog.record_tuples[0][2] == "No 'xaod' backend type found, " \ "using http://my-left-foot.com:5000 - please add to " \ "the configuration file (e.g. servicex.yaml)"
def test_sx_adaptor_settings_no_backend_name_requested_or_listed(caplog): 'Request None for a backend name' from confuse import Configuration c = Configuration('bogus', 'bogus') c.clear() c['api_endpoints'] = [{ 'endpoint': 'http://my-left-foot.com:5000', 'token': 'forkingshirtballs.thegoodplace.bortles' }] x = ServiceXConfigAdaptor(c) endpoint, token = x.get_servicex_adaptor_config() assert endpoint == 'http://my-left-foot.com:5000' assert token == 'forkingshirtballs.thegoodplace.bortles' assert caplog.record_tuples[0][2] == "No backend type requested, " \ "using http://my-left-foot.com:5000 - please be " \ "explicit " \ "in the ServiceXDataset constructor"
def test_sx_adaptor_settings_env(): from confuse import Configuration c = Configuration('bogus', 'bogus') c.clear() c['api_endpoints'] = [{ 'type': '${SXTYPE}', 'endpoint': '${ENDPOINT}:5000', 'token': '${SXTOKEN}', }] from os import environ environ['ENDPOINT'] = 'http://tachi.com' environ['SXTYPE'] = 'mcrn' environ['SXTOKEN'] = 'protomolecule' x = ServiceXConfigAdaptor(c) endpoint, token = x.get_servicex_adaptor_config('mcrn') assert endpoint == 'http://tachi.com:5000' assert token == 'protomolecule'