import unittest
from unittest.mock import patch
from RubrikSonarFileHits import entryTypes, formats, main
class TestMain(unittest.TestCase):
@patch("demistomock.context")
@patch("demistomock.results")
def test_main_with_no_radar_open_access_files(self, mock_results, mock_context):
# Test case: When there are no radar open access files
mock_context.return_value = {"Rubrik": {"Sonar": {"filesWithHits": None}}}
# Call the main function
main()
# Assert the results
mock_results.assert_called_with(
{
"ContentsFormat": formats["html"],
"Type": entryTypes["note"],
"Contents": (
"
None
"
),
}
)
@patch("demistomock.context")
@patch("demistomock.results")
def test_main_with_radar_open_access_files(self, mock_results, mock_context):
# Test case: When there are radar open access files
mock_context.return_value = {"Rubrik": {"Sonar": {"filesWithHits": 1}}}
# Call the main function
main()
# Assert the results
mock_results.assert_called_with(
{
"ContentsFormat": formats["html"],
"Type": entryTypes["note"],
"Contents": ("1
"),
}
)
@patch("demistomock.context")
@patch("demistomock.results")
def test_main_with_key_error(self, mock_results, mock_context):
# Test case: When there is a KeyError
mock_context.side_effect = KeyError
# Call the main function
main()
# Assert the results
mock_results.assert_called_with(
{
"ContentsFormat": formats["html"],
"Type": entryTypes["note"],
"Contents": (
"No Results Found
"
),
}
)
if __name__ == "__main__":
unittest.main()