def test_override_api_url_from_env(monkeypatch): # arrange settings = { 'controls': { 'proofdock': { 'provider': { 'module': 'pdchaoskit.controls', 'type': 'python', 'arguments': { 'api_url': 'https://chaosapi.proofdock.io/' } } } } } monkeypatch.setenv("PROOFDOCK_API_URL", "https://api.from.env.io") # act update_settings_from_env(settings) # assert arguments = settings['controls']['proofdock']['provider'] \ .get('arguments', None) assert arguments is not None assert arguments.get('api_url') == "https://api.from.env.io" assert get_api_url(settings) == "https://api.from.env.io"
def client_session( verify_tls: bool = True, settings: Settings = None) -> Generator[Session, None, None]: # prepare auth token api_url = get_api_url(settings) api_token = get_api_token(settings, api_url) headers = { "Authorization": "Bearer {}".format(api_token), } with Session() as s: s.base_url = api_url s.headers.update(headers) s.verify = verify_tls yield s
def test_get_api_url(): # arrange settings = { 'controls': { 'proofdock': { 'provider': { 'module': 'pdchaoskit.controls', 'type': 'python', 'arguments': { 'api_url': "https://some.api.io" } } } } } # act & assert assert get_api_url(settings) == "https://some.api.io"
def base() -> str: return get_api_url(get_loaded_settings())