diff --git a/tests/test_cli_helpers.py b/tests/test_cli_helpers.py index 1587c78..8cad7a9 100644 --- a/tests/test_cli_helpers.py +++ b/tests/test_cli_helpers.py @@ -70,3 +70,58 @@ def test_flag_cmd_exemption(capsys): finally: write_config(original_config, str(config_file)) # }}} + +# {{{ test_flag_cmd_list_format +def test_flag_cmd_list_format(): + """ + Verifies that ctf flag --list / -l prints the current flag format. + """ + from ctf.main import cli + + config_file = Path("/home/venus/code/ctf/config.toml") + original_config = load_config(str(config_file)) + + try: + temp_config = load_config(str(config_file)) + if "Competition" not in temp_config: + temp_config["Competition"] = {} + temp_config["Competition"]["flag_format"] = "TEST_FORMAT{[a-z]+}" + write_config(temp_config, str(config_file)) + + runner = CliRunner() + + # Test standard output + result = runner.invoke(cli, ["flag", "-l"]) + assert result.exit_code == 0 + assert "Current flag format: TEST_FORMAT{[a-z]+}" in result.output + + # Test plain output + result_plain = runner.invoke(cli, ["flag", "-l", "-p"]) + assert result_plain.exit_code == 0 + assert result_plain.output.strip() == "TEST_FORMAT{[a-z]+}" + finally: + write_config(original_config, str(config_file)) +# }}} + +# {{{ test_flag_cmd_set_format +def test_flag_cmd_set_format(): + """ + Verifies that ctf flag --set / -s updates the flag format in config.toml. + """ + from ctf.main import cli + + config_file = Path("/home/venus/code/ctf/config.toml") + original_config = load_config(str(config_file)) + + try: + runner = CliRunner() + result = runner.invoke(cli, ["flag", "-s", "NEW_FLAG_FORMAT{[0-9]+}"]) + assert result.exit_code == 0 + assert "Flag format set to: NEW_FLAG_FORMAT{[0-9]+}" in result.output + + updated_config = load_config(str(config_file)) + assert updated_config["Competition"]["flag_format"] == "NEW_FLAG_FORMAT{[0-9]+}" + finally: + write_config(original_config, str(config_file)) +# }}} +