def cli_runner_isolated(request, monkeypatch): fixture_path = fixtures_path / "isolated_config_dir" runner = CliRunner() with runner.isolated_filesystem() as isolated_dir: isolated_base_dir = isolated_dir isolated_xdg_config_home_dir = os.path.join(isolated_dir, ".config") isolated_ultron_config_dir = os.path.join(isolated_xdg_config_home_dir, "ultron8") isolated_ultron_config_path = os.path.join(isolated_ultron_config_dir, "smart.yaml") os.makedirs(isolated_xdg_config_home_dir) os.makedirs(isolated_ultron_config_dir) request.cls.home = isolated_base_dir request.cls.xdg_config_home = isolated_xdg_config_home_dir request.cls.ultron_config_dir = isolated_ultron_config_dir request.cls.ultron_config_path = isolated_ultron_config_path monkeypatch.setenv("HOME", request.cls.home) monkeypatch.setenv("XDG_CONFIG_HOME", request.cls.xdg_config_home) monkeypatch.setenv("ULTRON8DIR", request.cls.ultron_config_dir) # Copy the project fixture into the isolated filesystem dir. shutil.copytree(fixture_path, isolated_ultron_config_dir) # Monkeypatch a helper method onto the runner to make running commands # easier. runner.run = lambda command: runner.invoke(cli, command.split()) # And another for checkout the text output by the command. runner.output_of = lambda command: runner.run(command).output yield runner, isolated_dir
def test_cli_workspace_no_args(self, request, monkeypatch) -> None: # reset global config singleton config._CONFIG = None fixture_path = fixtures_path / "isolated_config_dir" print(fixture_path) runner = CliRunner() with runner.isolated_filesystem() as isolated_dir: # Populate filesystem folders isolated_base_dir = isolated_dir isolated_xdg_config_home_dir = os.path.join( isolated_dir, ".config") isolated_ultron_config_dir = os.path.join( isolated_xdg_config_home_dir, "ultron8") isolated_ultron_config_path = os.path.join( isolated_ultron_config_dir, "smart.yaml") # create base dirs os.makedirs(isolated_xdg_config_home_dir) # request.cls.home = isolated_base_dir # request.cls.xdg_config_home = isolated_xdg_config_home_dir # request.cls.ultron_config_dir = isolated_ultron_config_dir # request.cls.ultron_config_path = isolated_ultron_config_path # monkeypatch env vars to trick intgr tests into running only in isolated file system monkeypatch.setenv("HOME", isolated_base_dir) monkeypatch.setenv("XDG_CONFIG_HOME", isolated_xdg_config_home_dir) monkeypatch.setenv("ULTRON8DIR", isolated_ultron_config_dir) # Copy the project fixture into the isolated filesystem dir. shutil.copytree(fixture_path, isolated_ultron_config_dir) # Monkeypatch a helper method onto the runner to make running commands # easier. runner.run = lambda command: runner.invoke(cli, command.split()) # And another for checkout the text output by the command. runner.output_of = lambda command: runner.run(command).output # Run click test client result = runner.invoke(cli, ["workspace"]) # verify results assert result.exit_code == 0 assert "Usage: cli workspace [OPTIONS] COMMAND [ARGS]..." in result.output assert "Interact with workspace for ultron8." in result.output assert "Options:" in result.output assert "--help Show this message and exit." in result.output assert "Commands:" in result.output assert "info Info on workspace" in result.output assert "tree Tree command for Workspace" in result.output
def project_runner(fixture='simple'): fixture_path = (fixtures_path / 'projects' / fixture) runner = CliRunner() with runner.isolated_filesystem(): # Copy the project fixture into the isolated filesystem dir. shutil.copytree(fixture_path, '.tedi') # Monkeypatch a helper method onto the runner to make running commands # easier. runner.run = lambda command: runner.invoke(cli, command.split()) # And another for checkout the text output by the command. runner.output_of = lambda command: runner.run(command).output yield runner
def project_runner(fixture: str = "simple") -> Iterator[CliRunner]: fixture_path = fixtures_path / fixture runner = CliRunner() with runner.isolated_filesystem(): # Copy the project fixture into the isolated filesystem dir. shutil.copytree(fixture_path, ".ultron8") # Monkeypatch a helper method onto the runner to make running commands # easier. runner.run = lambda command: runner.invoke(cli, command.split()) # And another for checkout the text output by the command. runner.output_of = lambda command: runner.run(command).output yield runner
def test_cli_workspace_tree(self, request, monkeypatch) -> None: # reset global config singleton config._CONFIG = None fixture_path = fixtures_path / "isolated_config_dir" print(fixture_path) runner = CliRunner() with runner.isolated_filesystem() as isolated_dir: # Populate filesystem folders isolated_base_dir = isolated_dir isolated_xdg_config_home_dir = os.path.join( isolated_dir, ".config") isolated_ultron_config_dir = os.path.join( isolated_xdg_config_home_dir, "ultron8") isolated_ultron_config_path = os.path.join( isolated_ultron_config_dir, "smart.yaml") # create base dirs os.makedirs(isolated_xdg_config_home_dir) # request.cls.home = isolated_base_dir # request.cls.xdg_config_home = isolated_xdg_config_home_dir # request.cls.ultron_config_dir = isolated_ultron_config_dir # request.cls.ultron_config_path = isolated_ultron_config_path # monkeypatch env vars to trick intgr tests into running only in isolated file system monkeypatch.setenv("HOME", isolated_base_dir) monkeypatch.setenv("XDG_CONFIG_HOME", isolated_xdg_config_home_dir) monkeypatch.setenv("ULTRON8DIR", isolated_ultron_config_dir) # Copy the project fixture into the isolated filesystem dir. shutil.copytree(fixture_path, isolated_ultron_config_dir) # Grab access token r = get_superuser_jwt_request() tokens = r.json() a_token = tokens["access_token"] example_data = """ clusters_path: clusters/ cache_path: cache/ workspace_path: workspace/ templates_path: templates/ flags: debug: 0 verbose: 0 keep: 0 stderr: 0 repeat: 1 clusters: instances: local: url: http://localhost:11267 token: '{}' """.format(a_token) # overwrite smart.yaml w/ config that has auth token in it. helper_write_yaml_to_disk(example_data, isolated_ultron_config_path) # Monkeypatch a helper method onto the runner to make running commands # easier. runner.run = lambda command: runner.invoke(cli, command.split()) # And another for checkout the text output by the command. runner.output_of = lambda command: runner.run(command).output # Run click test client result = runner.invoke(cli, ["--debug", "workspace", "tree"]) print(result) # verify results assert result.exit_code == 0
def test_cli_user_list(self, request, monkeypatch) -> None: # reset global config singleton config._CONFIG = None fixture_path = fixtures_path / "isolated_config_dir" print(fixture_path) runner = CliRunner() with runner.isolated_filesystem() as isolated_dir: # Populate filesystem folders isolated_base_dir = isolated_dir isolated_xdg_config_home_dir = os.path.join( isolated_dir, ".config") isolated_ultron_config_dir = os.path.join( isolated_xdg_config_home_dir, "ultron8") isolated_ultron_config_path = os.path.join( isolated_ultron_config_dir, "smart.yaml") # create base dirs os.makedirs(isolated_xdg_config_home_dir) # request.cls.home = isolated_base_dir # request.cls.xdg_config_home = isolated_xdg_config_home_dir # request.cls.ultron_config_dir = isolated_ultron_config_dir # request.cls.ultron_config_path = isolated_ultron_config_path # monkeypatch env vars to trick intgr tests into running only in isolated file system monkeypatch.setenv("HOME", isolated_base_dir) monkeypatch.setenv("XDG_CONFIG_HOME", isolated_xdg_config_home_dir) monkeypatch.setenv("ULTRON8DIR", isolated_ultron_config_dir) # Copy the project fixture into the isolated filesystem dir. shutil.copytree(fixture_path, isolated_ultron_config_dir) # Grab access token r = get_superuser_jwt_request() tokens = r.json() a_token = tokens["access_token"] example_data = """ clusters_path: clusters/ cache_path: cache/ workspace_path: workspace/ templates_path: templates/ flags: debug: 0 verbose: 0 keep: 0 stderr: 0 repeat: 1 clusters: instances: local: url: http://localhost:11267 token: '{}' """.format(a_token) # overwrite smart.yaml w/ config that has auth token in it. helper_write_yaml_to_disk(example_data, isolated_ultron_config_path) # Monkeypatch a helper method onto the runner to make running commands # easier. runner.run = lambda command: runner.invoke(cli, command.split()) # And another for checkout the text output by the command. runner.output_of = lambda command: runner.run(command).output # Run click test client result = runner.invoke( cli, ["user", "--cluster", "local", "list", "--output", "table"]) print(result) # verify results assert result.exit_code == 0 # NOTE: This regex grabs the header # (?:ID)\s+\S\s+(?:Full Name)\s+\S\s+(?:Email)\s+\S\s+(?:Is Active)\s+\S\s+(?:Is Superuser)\s+\S\s+ # (?:1)\s+\S\s+(?:None)\s+\S\s+(?:[email protected])\s+\S\s+(?:True)\s+\S\s+(?:True)\s+\S\s+ # FIXME: need to set window size to correctly get result back from this # assert "╔═════╦═══════════╦══════════════════════════════════╦═══════════╦══════════════╗" in result.output # assert "║ ID ║ Full Name ║ Email ║ Is Active ║ Is Superuser ║" in result.output # assert "╠═════╬═══════════╬══════════════════════════════════╬═══════════╬══════════════╣" in result.output # assert "║ 1 ║ None ║ [email protected] ║ True ║ True ║" in result.output # assert "╠═════╬═══════════╬══════════════════════════════════╬═══════════╬══════════════╣" in result.output result_lines = result.output.split("\n") find_str = [] for i in range(0, 10): if "║ID║Email║FullName║IsActive║IsSuperuser║" in result_lines[ i].replace(" ", ""): find_str.append(result_lines[i]) if "║1║[email protected]║None║True║True║" in result_lines[ i].replace(" ", ""): find_str.append(result_lines[i]) # should have found the header and the first tet user. assert len(find_str) == 2
def test_cli_default_no_args(request, monkeypatch) -> None: # reset global config singleton config._CONFIG = None fixture_path = fixtures_path / "isolated_config_dir" print(fixture_path) runner = CliRunner() with runner.isolated_filesystem() as isolated_dir: # Populate filesystem folders isolated_base_dir = isolated_dir isolated_xdg_config_home_dir = os.path.join(isolated_dir, ".config") isolated_ultron_config_dir = os.path.join(isolated_xdg_config_home_dir, "ultron8") isolated_ultron_config_path = os.path.join(isolated_ultron_config_dir, "smart.yaml") # create base dirs os.makedirs(isolated_xdg_config_home_dir) # request.cls.home = isolated_base_dir # request.cls.xdg_config_home = isolated_xdg_config_home_dir # request.cls.ultron_config_dir = isolated_ultron_config_dir # request.cls.ultron_config_path = isolated_ultron_config_path # monkeypatch env vars to trick intgr tests into running only in isolated file system monkeypatch.setenv("HOME", isolated_base_dir) monkeypatch.setenv("XDG_CONFIG_HOME", isolated_xdg_config_home_dir) monkeypatch.setenv("ULTRON8DIR", isolated_ultron_config_dir) # Copy the project fixture into the isolated filesystem dir. shutil.copytree(fixture_path, isolated_ultron_config_dir) # Monkeypatch a helper method onto the runner to make running commands # easier. runner.run = lambda command: runner.invoke(cli, command.split()) # And another for checkout the text output by the command. runner.output_of = lambda command: runner.run(command).output # Run click test client result = runner.invoke(cli, ["--help"]) # verify results assert result.exit_code == 0 assert "Usage: cli [OPTIONS] COMMAND [ARGS]..." in result.output assert ( "Ultronctl - Client Side CLI tool to manage an Ultron8 Cluster." in result.output) assert "Options:" in result.output assert "--working-dir TEXT" in result.output assert "--config-dir TEXT" in result.output assert "--debug" in result.output assert "-v, --verbose Enables verbose mode." in result.output assert "--help Show this message and exit." in result.output assert "Commands:" in result.output assert "cluster Manage your ultron8 clusters" in result.output assert "config Manage your ultron8 config" in result.output assert "dummy Dummy command, doesn't do anything." in result.output assert "info Get info on running Ultron8 process" in result.output assert ("init Init cmd to setup workspace etc for ultron8." in result.output) assert "login Login to ultron8 cluster" in result.output assert "metrics Login to ultron8 cluster" in result.output assert "node Manage your ultron8 nodes" in result.output assert "user User CLI. Used to interact with ultron8 api" in result.output assert "version Get version" in result.output assert ("workspace All commands dealing with workspace for ultron8" in result.output)