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 50dcbf7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 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 @@ -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 50dcbf7

Please sign in to comment.