Skip to content

Commit

Permalink
feat: updating compdef list to required
Browse files Browse the repository at this point in the history
  • Loading branch information
hbraswelrh committed Dec 4, 2024
1 parent 4226a86 commit 66f55c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
30 changes: 23 additions & 7 deletions tests/trestlebot/cli/test_create_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def test_invalid_create_cmd() -> None:

def test_create_ssp_cmd(tmp_init_dir: str) -> None:
"""Tests successful create ssp command."""
SSP_INDEX_FILE = "tmp_init_dir/tester-ssp-index.json"
compdef_list_tester = ["ac-12", "ac-13"]
ssp_index_tester = "tmp_init_dir/tester-ssp-index.json"

runner = CliRunner()
result = runner.invoke(
Expand All @@ -30,12 +31,14 @@ def test_create_ssp_cmd(tmp_init_dir: str) -> None:
"oscal-profile-name",
"--markdown-dir",
"markdown",
"--compdefs",
compdef_list_tester,
"--ssp-name",
"test-name",
"--repo-path",
tmp_init_dir,
"--ssp-index-file",
SSP_INDEX_FILE,
ssp_index_tester,
],
)
assert result.exit_code == 0
Expand Down Expand Up @@ -68,6 +71,9 @@ def test_create_compdef_cmd(tmp_init_dir: str) -> None:

def test_default_ssp_index_file_cmd(tmp_init_dir: str) -> None:
"""Tests successful default ssp_index.json file creation."""
compdef_list_tester = ["ac-12", "ac-13"]
default_ssp_index_file = "tmp_init_dir/test-ssp-index.json"

runner = CliRunner()
result = runner.invoke(
create_cmd,
Expand All @@ -77,18 +83,23 @@ def test_default_ssp_index_file_cmd(tmp_init_dir: str) -> None:
"oscal-profile-name",
"--markdown-dir",
"markdown",
"--compdefs",
compdef_list_tester,
"--ssp-name",
"test-name",
"--repo-path",
tmp_init_dir,
"--ssp-index-file",
default_ssp_index_file,
],
)
assert result.exit_code == 0


def test_markdown_files_not_created(tmp_init_dir: str) -> None:
"""Tests failure of markdown file creation when not supplied with directory name."""
SSP_INDEX_TESTER = "tmp_init_dir/ssp-tester.index.json"
compdef_list_tester = ["ac-12", "ac-13"]
ssp_index_tester = "tmp_init_dir/ssp-tester.index.json"

runner = CliRunner()
result = runner.invoke(
Expand All @@ -97,21 +108,24 @@ def test_markdown_files_not_created(tmp_init_dir: str) -> None:
"ssp",
"--profile-name",
"oscal-profile-name",
"--compdefs",
compdef_list_tester,
"--ssp-name",
"test-name",
"repo-path",
tmp_init_dir,
"--ssp-index-file",
SSP_INDEX_TESTER,
ssp_index_tester,
],
)
assert result.exit_code == 2


def test_markdown_files_created(tmp_init_dir: str) -> None:
"""Tests successful creation of markdown files."""
SSP_INDEX_TESTER = "tmp_init_dir/ssp-tester.index.json"
markdown_file_tester = "/markdown/system-security-plan.md"
ssp_index_tester = "tmp_init_dir/ssp-tester.index.json"
markdown_file_tester = "tmp_init_dir/markdown/system-security-plan.md"
compdef_list_tester = ["ac-12", "ac-13"]

runner = CliRunner()
result = runner.invoke(
Expand All @@ -122,12 +136,14 @@ def test_markdown_files_created(tmp_init_dir: str) -> None:
"oscal-profile-name",
"--markdown-dir",
markdown_file_tester,
"--compdefs",
compdef_list_tester,
"--ssp-name",
"test-name",
"--repo-path",
tmp_init_dir,
"--ssp-index-file",
SSP_INDEX_TESTER,
ssp_index_tester,
],
)
assert result.exit_code == 0
3 changes: 2 additions & 1 deletion trestlebot/cli/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ def compdef_cmd(
)
@click.option(
"--compdefs",
required=False,
required=True,
type=str,
prompt="Enter comma separated list of component definitions to include in SSP",
help="Comma separated list of component definitions.",
)
@handle_exceptions
Expand Down

0 comments on commit 66f55c7

Please sign in to comment.