def test_verbose(): args = parse_arguments([ "user-create", "--name", "toto", "--password", "toto", "--email", "*****@*****.**", ]) assert args.verbose is False args = parse_arguments([ "user-create", "--verbose", "--name", "toto", "--password", "toto", "--email", "*****@*****.**", ]) assert args.verbose is True args = parse_arguments([ "user-create", "--long", "--name", "toto", "--password", "toto", "--email", "*****@*****.**", ]) assert args.verbose is True
def test_parse_arguments_format(): args = parse_arguments(["--format", "json", "user-list"]) assert args.format == "json" args = parse_arguments(["--format", "csv", "user-list"]) assert args.format == "csv" args = parse_arguments(["--format", "tsv", "user-list"]) assert args.format == "tsv" args = parse_arguments(["user-list"]) assert args.format == "table"
def test_parse_arguments_version(exit_function, capsys): parse_arguments(["--version", "user-list"]) captured = capsys.readouterr() # Note(hguemar): argparse behaviour here changed on py3k if sys.version_info > (3, 0): captured = captured.out else: captured = captured.err assert captured == "dcictl {}\n".format(__version__) assert exit_function.called
def test_parse_arguments_user_create_mutually_exclusive_boolean_flags( exit_function): with raises(TypeError): parse_arguments([ "user-create", "--name", "foo", "--password", "bar", "--email", "*****@*****.**", "--active", "--no-active", ]) assert exit_function.called
def test_parse_arguments_user_update(): args = parse_arguments( ["user-update", "u1", "--etag", "e1", "--name", "new_name"]) assert args.command == "user-update" assert args.id == "u1" assert args.etag == "e1" assert args.name == "new_name"
def test_parse_arguments_user_list_defaults(): args = parse_arguments(["user-list"]) assert args.command == "user-list" assert args.sort == "-created_at" assert args.limit == 50 assert args.offset == 0 assert args.where is None assert args.verbose is False
def test_parse_arguments_user_create_required_args_no_exit(exit_function): args = parse_arguments([ "user-create", "--name", "foo", "--password", "bar", "--email", "*****@*****.**" ]) assert args.command == "user-create" assert args.name == "foo" assert args.password == "bar" assert args.email == "*****@*****.**" assert not exit_function.called
def test_parse_arguments_user_create_boolean_flags(): args = parse_arguments([ "user-create", "--name", "foo", "--password", "bar", "--email", "*****@*****.**", "--active", ]) assert args.state args = parse_arguments([ "user-create", "--name", "foo", "--password", "bar", "--email", "*****@*****.**", "--no-active", ]) assert args.state is False
def test_parse_arguments_sso_env(): args = parse_arguments( ["user-list"], { "SSO_URL": "https://sso.redhat.com", "SSO_USERNAME": "******", "SSO_PASSWORD": "******", }, ) assert args.sso_url == "https://sso.redhat.com" assert args.sso_username == "sso" assert args.sso_password == "sso" assert args.sso_token is None assert args.refresh_sso_token is False
def test_parse_arguments_sso(): args = parse_arguments( [ "--sso-url", "https://sso.redhat.com", "--sso-username", "dci", "--sso-password", "dci", "user-list", ], {}, ) assert args.sso_url == "https://sso.redhat.com" assert args.sso_username == "dci" assert args.sso_password == "dci" assert args.sso_token is None assert args.refresh_sso_token is False
def main(): args = parse_arguments(sys.argv[1:], os.environ) dci_cs_url = args.dci_cs_url dci_login = args.dci_login dci_password = args.dci_password context = None if dci_login is not None and dci_password is not None: context = dci_context.build_dci_context(dci_login=dci_login, dci_password=dci_password, dci_cs_url=dci_cs_url) sso_url = args.sso_url sso_username = args.sso_username sso_password = args.sso_password sso_token = args.sso_token refresh_sso_token = args.refresh_sso_token if (sso_url is not None and sso_username is not None and sso_password is not None) or sso_token is not None: context = dci_context.build_sso_context( dci_cs_url, sso_url, sso_username, sso_password, sso_token, refresh=refresh_sso_token, ) dci_client_id = args.dci_client_id dci_api_secret = args.dci_api_secret if dci_client_id is not None and dci_api_secret is not None: context = dci_context.build_signature_context( dci_cs_url=dci_cs_url, dci_client_id=dci_client_id, dci_api_secret=dci_api_secret, ) if not context: print("No credentials provided.") sys.exit(1) response = run(context, args) print_response(response, args.format, args.verbose)
def test_parse_arguments_dci_client_id_from_env(): args = parse_arguments(["user-list"], {"DCI_CLIENT_ID": "foo"}) assert args.dci_client_id == "foo"
def test_parse_arguments_dci_client_id_overload_from_env(): args = parse_arguments(["--dci-client-id", "bar", "user-list"], {"DCI_CLIENT_ID": "foo"}) assert args.dci_client_id == "bar"
def test_parse_arguments_dci_password_overload_from_env(): args = parse_arguments(["--dci-password", "bar", "user-list"], {"DCI_PASSWORD": "******"}) assert args.dci_password == "bar"
def test_parse_arguments_dci_client_id(): args = parse_arguments(["--dci-client-id", "foo", "user-list"]) assert args.dci_client_id == "foo"
def test_parse_arguments_dci_password(): args = parse_arguments(["--dci-password", "foo", "user-list"]) assert args.dci_password == "foo"
def test_parse_arguments_dci_password_from_env(): args = parse_arguments(["user-list"], {"DCI_PASSWORD": "******"}) assert args.dci_password == "foo"
def test_parse_arguments_dci_cs_url_from_env(): args = parse_arguments(["user-list"], {"DCI_CS_URL": "foo"}) assert args.dci_cs_url == "foo"
def test_parse_arguments_dci_login_overload_from_env(): args = parse_arguments(["--dci-login", "bar", "user-list"], {"DCI_LOGIN": "******"}) assert args.dci_login == "bar"
def test_parse_arguments_dci_api_secret(): args = parse_arguments(["--dci-api-secret", "foo", "user-list"]) assert args.dci_api_secret == "foo"
def invoke(arguments): environment = {} args = cli.parse_arguments(arguments, environment) response = dci_runner.run(context, args) return response.json() if response else None
def test_parse_arguments_dci_cs_url_overload_from_env(): args = parse_arguments(["--dci-cs-url", "bar", "user-list"], {"DCI_CS_URL": "foo"}) assert args.dci_cs_url == "bar"
def test_parse_arguments_dci_api_secret_overload_from_env(): args = parse_arguments(["--dci-api-secret", "bar", "user-list"], {"DCI_API_SECRET": "foo"}) assert args.dci_api_secret == "bar"
def test_parse_arguments_sso_token_env(): args = parse_arguments(["user-list"], {"SSO_TOKEN": "efg"}) assert args.sso_token == "efg" assert args.refresh_sso_token is False
def test_parse_arguments_sso_token(): args = parse_arguments( ["--sso-token", "abc", "--refresh-sso-token", "user-list"], {}) assert args.refresh_sso_token assert args.sso_token == "abc"
def test_parse_arguments_dci_cs_url_default(): args = parse_arguments(["user-list"]) assert args.dci_cs_url == _default_dci_cs_url
def test_parse_arguments_dci_login(): args = parse_arguments(["--dci-login", "foo", "user-list"], {"DCI_LOGIN": "******"}) assert args.dci_login == "foo"
def test_parse_arguments_dci_login_from_env(): args = parse_arguments(["user-list"], {"DCI_LOGIN": "******"}) assert args.dci_login == "foo"
def invoke_raw(arguments): environment = {} args = cli.parse_arguments(arguments, environment) return dci_runner.run(context, args)
def test_parse_arguments_dci_cs_url(): args = parse_arguments(["--dci-cs-url", "foo", "user-list"]) assert args.dci_cs_url == "foo"