50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
from pathlib import Path
|
|
import toml
|
|
from click.testing import CliRunner
|
|
from ctf.commands import basic_group
|
|
|
|
TEST_ENV = Path("tests/env")
|
|
|
|
def test_basic_test_cli():
|
|
"""
|
|
Verifies that 'basic test' runs successfully and outputs 'hello from test'.
|
|
"""
|
|
runner = CliRunner()
|
|
result = runner.invoke(basic_group, ["test"])
|
|
assert result.exit_code == 0
|
|
assert "hello from test" in result.output
|
|
|
|
def test_basic_greet_cli():
|
|
"""
|
|
Verifies that 'basic greet' runs successfully and greets the name argument.
|
|
"""
|
|
runner = CliRunner()
|
|
result = runner.invoke(basic_group, ["greet", "Alice"])
|
|
assert result.exit_code == 0
|
|
assert "hello Alice" in result.output
|
|
|
|
def test_basic_set_flag_format_cli():
|
|
"""
|
|
Verifies that 'basic set-flag-format' CLI command writes the pattern to config.toml.
|
|
"""
|
|
from ctf.utils import load_config
|
|
|
|
runner = CliRunner()
|
|
config_file = Path("/home/venus/code/ctf/config.toml")
|
|
|
|
# Save the original config to restore later
|
|
original_config = load_config(str(config_file))
|
|
|
|
try:
|
|
result = runner.invoke(basic_group, ["set-flag-format", "TEST_FLAG{[a-z]+}"])
|
|
assert result.exit_code == 0
|
|
assert "Flag format set to" in result.output
|
|
|
|
# Verify it was written to config.toml
|
|
updated_config = load_config(str(config_file))
|
|
assert updated_config["Competition"]["flag_format"] == "TEST_FLAG{[a-z]+}"
|
|
finally:
|
|
# Restore original config
|
|
from ctf.utils import write_config
|
|
write_config(original_config, str(config_file))
|