Skip to content

Commit

Permalink
test: adds unit test for validate_args with invalid model
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Dec 15, 2023
1 parent 7aabd1d commit 1b33b79
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/trestlebot/entrypoints/test_autosync.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

"""Test for Autosync CLI"""

import argparse
import logging
from typing import Any, Dict
from unittest.mock import patch

import pytest

from tests.testutils import args_dict_to_list
from trestlebot.entrypoints.autosync import AutoSyncEntrypoint
from trestlebot.entrypoints.autosync import main as cli_main
from trestlebot.entrypoints.entrypoint_base import EntrypointInvalidArgException


@pytest.fixture
Expand All @@ -39,7 +42,7 @@ def valid_args_dict() -> Dict[str, str]:
}


def test_invalid_oscal_model(valid_args_dict: Dict[str, str]) -> None:
def test_invalid_oscal_model(valid_args_dict: Dict[str, str], caplog: Any) -> None:
"""Test invalid oscal model"""
args_dict = valid_args_dict
args_dict["oscal-model"] = "fake"
Expand All @@ -48,6 +51,26 @@ def test_invalid_oscal_model(valid_args_dict: Dict[str, str]) -> None:
cli_main()


def test_validate_args_invalid_model(valid_args_dict: Dict[str, str]) -> None:
"""
Test invalid oscal model with validate args function.
This is a separate test from test_invalid_oscal_model because
it args are make invalid after the args are parsed.
"""
args_dict = valid_args_dict
with patch("sys.argv", ["trestlebot", *args_dict_to_list(args_dict)]):
with pytest.raises(
EntrypointInvalidArgException,
match="Invalid args --oscal-model: Invalid value fake. "
"Please use one of catalog, profile, ssp, compdef",
):
parser = argparse.ArgumentParser()
auto_sync = AutoSyncEntrypoint(parser=parser)
args = parser.parse_args()
args.oscal_model = "fake"
auto_sync.validate_args(args)


def test_no_ssp_index(valid_args_dict: Dict[str, str], caplog: Any) -> None:
"""Test missing index file for ssp"""
args_dict = valid_args_dict
Expand Down

0 comments on commit 1b33b79

Please sign in to comment.