Skip to content

Commit

Permalink
test: updated unit and integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
hetangmodi-crest committed Nov 20, 2024
1 parent 1df48e7 commit 87a2d34
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 14 deletions.
33 changes: 29 additions & 4 deletions tests/integration/test_conf_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,21 +193,46 @@ def test_invalid_proxy_port():
logger=mock.MagicMock(),
session_key=session_key,
app_name="solnlib_demo",
conf_name="splunk_ta_addon_settings_invalid",
proxy_stanza="invalid_proxy",
proxy_port="proxy_port",
conf_name="splunk_ta_addon_settings",
proxy_stanza="proxy",
proxy_port="invalid_port",
)


def test_invalid_proxy_host():
session_key = context.get_session_key()

with pytest.raises(soln_exceptions.InvalidHostnameError):
conf_manager.get_proxy_dict(
logger=mock.MagicMock(),
session_key=session_key,
app_name="solnlib_demo",
conf_name="splunk_ta_addon_settings",
proxy_stanza="proxy",
proxy_host="proxy_url",
)


def test_conf_manager_exception():
session_key = context.get_session_key()

with pytest.raises(soln_exceptions.ConfManagerException):
conf_manager.get_proxy_dict(
logger=mock.MagicMock(),
session_key=session_key,
app_name="solnlib_demo",
conf_name="splunk_ta_addon_settings_invalid",
)


def test_conf_stanza_not_exist_exception():
session_key = context.get_session_key()

with pytest.raises(soln_exceptions.ConfStanzaNotExistException):
conf_manager.get_proxy_dict(
logger=mock.MagicMock(),
session_key=session_key,
app_name="solnlib_demo",
conf_name="splunk_ta_addon_settings",
proxy_stanza="invalid_proxy",
proxy_host="proxy_url",
)
36 changes: 26 additions & 10 deletions tests/unit/test_conf_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,31 @@ def test_get_proxy_dict_conf_manager_exception(mock_conf_manager_class):
mock_conf_manager = mock_conf_manager_class.return_value
mock_conf_manager.get_conf.side_effect = ConfManagerException

logger = mock.MagicMock()
proxy_dict = conf_manager.get_proxy_dict(
logger=logger,
session_key="session_key",
app_name="app_name",
conf_name="conf_name",
)
with pytest.raises(
ConfManagerException, match="Failed to fetch configuration file 'conf_name'."
):
conf_manager.get_proxy_dict(
logger=mock.MagicMock(),
session_key="session_key",
app_name="app_name",
conf_name="conf_name",
)


logger.error.assert_called_once_with(
"Failed to fetch configuration file 'conf_name'."
@mock.patch.object(conf_manager, "ConfManager")
def test_get_proxy_dict_conf_stanza_exception(mock_conf_manager_class):
mock_conf_manager = mock_conf_manager_class.return_value
mock_conf_manager.get_conf.return_value.get.side_effect = (
ConfStanzaNotExistException
)
assert proxy_dict == {}
with pytest.raises(
ConfStanzaNotExistException,
match="Failed to fetch 'custom_stanza' from the configuration file 'conf_name'. ",
):
conf_manager.get_proxy_dict(
logger=mock.MagicMock(),
session_key="session_key",
app_name="app_name",
conf_name="conf_name",
proxy_stanza="custom_stanza",
)

0 comments on commit 87a2d34

Please sign in to comment.