Skip to content

Commit 687b82f

Browse files
test(unit): add test when splunk isn't imported
1 parent 89cb2b0 commit 687b82f

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

tests/unit/conftest.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/unit/test_server_info.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,32 @@ def test_server_info_object_with_key_file(
161161
assert kwargs.get("cert_file") is None
162162
assert kwargs.get("key_file") is None
163163
assert kwargs.get("verify") is None
164+
165+
@patch("solnlib.server_info.os.environ", autospec=True, return_value="$SPLUNK_HOME")
166+
@patch(
167+
"solnlib.server_info.get_splunkd_access_info",
168+
autospec=True,
169+
return_value=("https", "127.0.0.1", "8089"),
170+
)
171+
@patch("solnlib.server_info.rest_client", autospec=True)
172+
def test_server_info_object_with_no_splunk_import(
173+
self,
174+
mock_rest_client,
175+
mock_splunkd,
176+
mock_os_env,
177+
):
178+
mock_rest_client.SplunkRestClient = MagicMock()
179+
180+
# we want to raise 'ModuleNotFoundError' when importing the required functions
181+
with patch.dict("sys.modules", {"splunk": ModuleNotFoundError}):
182+
server_info.ServerInfo(common.SESSION_KEY)
183+
184+
for call_arg in mock_rest_client.SplunkRestClient.call_args_list:
185+
_, kwargs = call_arg
186+
assert (
187+
kwargs.get("cert_file") is None
188+
) # comes from the empty function in except
189+
assert (
190+
kwargs.get("key_file") is None
191+
) # comes from the empty function in except
192+
assert kwargs.get("verify") is None

0 commit comments

Comments
 (0)