Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use temporary directory in tests #291

Merged
1 commit merged into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions tests/data/test_ucc_generate.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import tempfile
import unittest
from os import path

Expand All @@ -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__":
Expand Down
193 changes: 98 additions & 95 deletions tests/unit/test_alert_actions_py_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"]
)