def login(profile_name=None, username=None, password=None, profile=None, do_prompt=True): if do_prompt and not (username and password): user, pass_ = prompt.retry_once_for_assertions(prompt.configure_login_info, coerce_password=True, query_password=False) if username and not password: pass_ = prompt.retry_once_for_assertions(prompt.configure_password_info) profile_name = getattr(profile, 'NAME', profile_name) pv_cli_utils.auth_action('login', profile_name, username=user, password=pass_)
def test_auth_action(self, mocker, profile, func): mapi = mocker.MagicMock(spec=PicovicoAPI) mocker.patch('picovico.cli.utils.prepare_api_object', return_value=mapi) data = { 'ACCESS_KEY': 'access_key', 'ACCESS_TOKEN': 'access_token', 'PROFILE': profile or DEFAULT_PROFILE_NAME } mws = mocker.patch('picovico.cli.utils.file_utils.write_to_session_file') mapi.is_authorized.return_value = False pv_utils.auth_action(func, profile) mws.assert_not_called() mapi.is_authorized.return_value = True for k in data: if '_' in k: setattr(mapi, k.lower(), data[k]) pv_utils.auth_action(func, profile) mws.assert_called_with(data)
def authenticate(profile_name=None, app_secret=None, profile=None, do_prompt=True): if do_prompt and not app_secret: app_secret = prompt.retry_once_for_assertions(prompt.configure_secret_info) profile_name = getattr(profile, 'NAME', profile_name) pv_cli_utils.auth_action('authenticate', profile_name, app_secret=app_secret)