diff --git a/tests/data/test_ucc_generate.py b/tests/data/test_ucc_generate.py index 2366137e3..c42e1b751 100644 --- a/tests/data/test_ucc_generate.py +++ b/tests/data/test_ucc_generate.py @@ -1,3 +1,4 @@ +import tempfile import unittest from os import path @@ -10,11 +11,9 @@ def test_ucc_generate(self): ucc.generate(source=package_folder) def test_ucc_generate_with_custom_output_folder(self): - package_folder = path.join(path.dirname(path.realpath(__file__)), "package") - output_folder = path.join( - path.dirname(path.realpath(__file__)), "custom_output" - ) - ucc.generate(source=package_folder, outputdir=output_folder) + with tempfile.TemporaryDirectory() as temp_dir: + package_folder = path.join(path.dirname(path.realpath(__file__)), "package") + ucc.generate(source=package_folder, outputdir=temp_dir) if __name__ == "__main__": diff --git a/tests/unit/test_alert_actions_py_gen.py b/tests/unit/test_alert_actions_py_gen.py index 287ac2716..feb6085bd 100644 --- a/tests/unit/test_alert_actions_py_gen.py +++ b/tests/unit/test_alert_actions_py_gen.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # -import os +import tempfile import unittest from unittest import mock @@ -25,102 +25,105 @@ class AlertActionsPyGenTest(unittest.TestCase): def test_generate_alert_action(self): - generated = alert_actions_py_gen.generate_alert_actions_py_files( - input_setting={ - "product_id": "Splunk_TA_UCCExample", - "short_name": "splunk_ta_uccexample", - "modular_alerts": [ - { - "label": "Test Alert", - "description": "Description for test Alert Action", - "short_name": "test_alert", - "active_response": { - "task": ["Create", "Update"], - "subject": ["endpoint"], - "category": [ - "Information Conveyance", - "Information Portrayal", - ], - "technology": [ - { - "version": ["1.0.0"], - "product": "Test Incident Update", - "vendor": "Splunk", - } - ], - "sourcetype": "test:incident", - "supports_adhoc": True, - "drilldown_uri": 'search?q=search%20index%3D"_internal"&earliest=0&latest=', - }, - "parameters": [ - { - "label": "Name", - "required": True, - "format_type": "text", - "name": "name", - "default_value": "xyz", - "help_string": "Please enter your name", - }, - { - "label": "All Incidents", - "required": False, - "format_type": "checkbox", - "name": "all_incidents", - "default_value": 0, - "help_string": "Tick if you want to update all incidents/problems", + with tempfile.TemporaryDirectory() as temp_dir: + generated = alert_actions_py_gen.generate_alert_actions_py_files( + input_setting={ + "product_id": "Splunk_TA_UCCExample", + "short_name": "splunk_ta_uccexample", + "modular_alerts": [ + { + "label": "Test Alert", + "description": "Description for test Alert Action", + "short_name": "test_alert", + "active_response": { + "task": ["Create", "Update"], + "subject": ["endpoint"], + "category": [ + "Information Conveyance", + "Information Portrayal", + ], + "technology": [ + { + "version": ["1.0.0"], + "product": "Test Incident Update", + "vendor": "Splunk", + } + ], + "sourcetype": "test:incident", + "supports_adhoc": True, + "drilldown_uri": 'search?q=search%20index%3D"_internal"&earliest=0&latest=', }, - { - "label": "Table List", - "required": False, - "format_type": "dropdownlist", - "name": "table_list", - "help_string": "Please select the table", - "default_value": "problem", - "possible_values": { - "incident": "Incident", - "problem": "Problem", + "parameters": [ + { + "label": "Name", + "required": True, + "format_type": "text", + "name": "name", + "default_value": "xyz", + "help_string": "Please enter your name", }, - }, - { - "label": "Action:", - "required": True, - "format_type": "radio", - "name": "action", - "help_string": "Select the action you want to perform", - "default_value": "two", - "possible_values": { - "update": "Update", - "delete": "Delete", + { + "label": "All Incidents", + "required": False, + "format_type": "checkbox", + "name": "all_incidents", + "default_value": 0, + "help_string": "Tick if you want to update all incidents/problems", }, - }, - { - "label": "Select Account", - "required": True, - "format_type": "dropdownlist_splunk_search", - "name": "account", - "help_string": "Select the account from the dropdown", - "ctrl_props": { - "value-field": "title", - "label-field": "title", - "search": "| rest /servicesNS/nobody/TA-SNOW/admin/TA_SNOW_account | dedup title", + { + "label": "Table List", + "required": False, + "format_type": "dropdownlist", + "name": "table_list", + "help_string": "Please select the table", + "default_value": "problem", + "possible_values": { + "incident": "Incident", + "problem": "Problem", + }, + }, + { + "label": "Action:", + "required": True, + "format_type": "radio", + "name": "action", + "help_string": "Select the action you want to perform", + "default_value": "two", + "possible_values": { + "update": "Update", + "delete": "Delete", + }, }, + { + "label": "Select Account", + "required": True, + "format_type": "dropdownlist_splunk_search", + "name": "account", + "help_string": "Select the account from the dropdown", + "ctrl_props": { + "value-field": "title", + "label-field": "title", + "search": "| rest /servicesNS/nobody/TA-SNOW/admin/TA_SNOW_account | dedup title", + }, + }, + ], + "alert_props": { + "python.version": "python3", + "is_custom": 1, + "payload_format": "json", }, - ], - "alert_props": { - "python.version": "python3", - "is_custom": 1, - "payload_format": "json", - }, - } - ], - }, - global_settings="", - logger=mock.MagicMock(), - package_path=os.path.dirname(__file__), - ) - expected_alert_helper = get_testdata_file("alert_action_helper.py.generated") - expected_alert = get_testdata_file("alert_action.py.generated") - self.assertEqual(expected_alert, generated["test_alert"]["test_alert.py"]) - self.assertEqual( - expected_alert_helper, generated["test_alert"]["test_alert_helper.py"] - ) + } + ], + }, + global_settings="", + logger=mock.MagicMock(), + package_path=temp_dir, + ) + expected_alert_helper = get_testdata_file( + "alert_action_helper.py.generated" + ) + expected_alert = get_testdata_file("alert_action.py.generated") + self.assertEqual(expected_alert, generated["test_alert"]["test_alert.py"]) + self.assertEqual( + expected_alert_helper, generated["test_alert"]["test_alert_helper.py"] + )