Reformat everything.

This commit is contained in:
Felix Fontein
2025-11-01 12:08:41 +01:00
parent 3f2213791a
commit 340ff8586d
1008 changed files with 61301 additions and 58309 deletions

View File

@@ -8,7 +8,10 @@ from __future__ import annotations
from ansible_collections.community.general.plugins.modules import datadog_downtime
from unittest.mock import MagicMock, patch
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
AnsibleExitJson,
AnsibleFailJson,
ModuleTestCase,
set_module_args,
)
from pytest import importorskip
@@ -20,7 +23,6 @@ DowntimeRecurrence = datadog_api_client.v1.model.downtime_recurrence.DowntimeRec
class TestDatadogDowntime(ModuleTestCase):
def setUp(self):
super().setUp()
self.module = datadog_downtime
@@ -36,18 +38,20 @@ class TestDatadogDowntime(ModuleTestCase):
@patch("ansible_collections.community.general.plugins.modules.datadog_downtime.DowntimesApi")
def test_create_downtime_when_no_id(self, downtimes_api_mock):
with set_module_args({
"monitor_tags": ["foo:bar"],
"scope": ["*"],
"monitor_id": 12345,
"downtime_message": "Message",
"start": 1111,
"end": 2222,
"timezone": "UTC",
"rrule": "rrule",
"api_key": "an_api_key",
"app_key": "an_app_key",
}):
with set_module_args(
{
"monitor_tags": ["foo:bar"],
"scope": ["*"],
"monitor_id": 12345,
"downtime_message": "Message",
"start": 1111,
"end": 2222,
"timezone": "UTC",
"rrule": "rrule",
"api_key": "an_api_key",
"app_key": "an_app_key",
}
):
downtime = Downtime()
downtime.monitor_tags = ["foo:bar"]
downtime.scope = ["*"]
@@ -56,35 +60,34 @@ class TestDatadogDowntime(ModuleTestCase):
downtime.start = 1111
downtime.end = 2222
downtime.timezone = "UTC"
downtime.recurrence = DowntimeRecurrence(
rrule="rrule",
type="rrule"
)
downtime.recurrence = DowntimeRecurrence(rrule="rrule", type="rrule")
create_downtime_mock = MagicMock(return_value=self.__downtime_with_id(12345))
downtimes_api_mock.return_value = MagicMock(create_downtime=create_downtime_mock)
with self.assertRaises(AnsibleExitJson) as result:
self.module.main()
self.assertTrue(result.exception.args[0]['changed'])
self.assertEqual(result.exception.args[0]['downtime']['id'], 12345)
self.assertTrue(result.exception.args[0]["changed"])
self.assertEqual(result.exception.args[0]["downtime"]["id"], 12345)
create_downtime_mock.assert_called_once_with(downtime)
@patch("ansible_collections.community.general.plugins.modules.datadog_downtime.DowntimesApi")
def test_create_downtime_when_id_and_disabled(self, downtimes_api_mock):
with set_module_args({
"id": 1212,
"monitor_tags": ["foo:bar"],
"scope": ["*"],
"monitor_id": 12345,
"downtime_message": "Message",
"start": 1111,
"end": 2222,
"timezone": "UTC",
"rrule": "rrule",
"api_key": "an_api_key",
"app_key": "an_app_key",
}):
with set_module_args(
{
"id": 1212,
"monitor_tags": ["foo:bar"],
"scope": ["*"],
"monitor_id": 12345,
"downtime_message": "Message",
"start": 1111,
"end": 2222,
"timezone": "UTC",
"rrule": "rrule",
"api_key": "an_api_key",
"app_key": "an_app_key",
}
):
downtime = Downtime()
downtime.monitor_tags = ["foo:bar"]
downtime.scope = ["*"]
@@ -93,10 +96,7 @@ class TestDatadogDowntime(ModuleTestCase):
downtime.start = 1111
downtime.end = 2222
downtime.timezone = "UTC"
downtime.recurrence = DowntimeRecurrence(
rrule="rrule",
type="rrule"
)
downtime.recurrence = DowntimeRecurrence(rrule="rrule", type="rrule")
disabled_downtime = Downtime()
disabled_downtime.disabled = True
@@ -110,26 +110,28 @@ class TestDatadogDowntime(ModuleTestCase):
with self.assertRaises(AnsibleExitJson) as result:
self.module.main()
self.assertTrue(result.exception.args[0]['changed'])
self.assertEqual(result.exception.args[0]['downtime']['id'], 12345)
self.assertTrue(result.exception.args[0]["changed"])
self.assertEqual(result.exception.args[0]["downtime"]["id"], 12345)
create_downtime_mock.assert_called_once_with(downtime)
get_downtime_mock.assert_called_once_with(1212)
@patch("ansible_collections.community.general.plugins.modules.datadog_downtime.DowntimesApi")
def test_update_downtime_when_not_disabled(self, downtimes_api_mock):
with set_module_args({
"id": 1212,
"monitor_tags": ["foo:bar"],
"scope": ["*"],
"monitor_id": 12345,
"downtime_message": "Message",
"start": 1111,
"end": 2222,
"timezone": "UTC",
"rrule": "rrule",
"api_key": "an_api_key",
"app_key": "an_app_key",
}):
with set_module_args(
{
"id": 1212,
"monitor_tags": ["foo:bar"],
"scope": ["*"],
"monitor_id": 12345,
"downtime_message": "Message",
"start": 1111,
"end": 2222,
"timezone": "UTC",
"rrule": "rrule",
"api_key": "an_api_key",
"app_key": "an_app_key",
}
):
downtime = Downtime()
downtime.monitor_tags = ["foo:bar"]
downtime.scope = ["*"]
@@ -138,10 +140,7 @@ class TestDatadogDowntime(ModuleTestCase):
downtime.start = 1111
downtime.end = 2222
downtime.timezone = "UTC"
downtime.recurrence = DowntimeRecurrence(
rrule="rrule",
type="rrule"
)
downtime.recurrence = DowntimeRecurrence(rrule="rrule", type="rrule")
enabled_downtime = Downtime()
enabled_downtime.disabled = False
@@ -155,26 +154,28 @@ class TestDatadogDowntime(ModuleTestCase):
with self.assertRaises(AnsibleExitJson) as result:
self.module.main()
self.assertTrue(result.exception.args[0]['changed'])
self.assertEqual(result.exception.args[0]['downtime']['id'], 1212)
self.assertTrue(result.exception.args[0]["changed"])
self.assertEqual(result.exception.args[0]["downtime"]["id"], 1212)
update_downtime_mock.assert_called_once_with(1212, downtime)
get_downtime_mock.assert_called_once_with(1212)
@patch("ansible_collections.community.general.plugins.modules.datadog_downtime.DowntimesApi")
def test_update_downtime_no_change(self, downtimes_api_mock):
with set_module_args({
"id": 1212,
"monitor_tags": ["foo:bar"],
"scope": ["*"],
"monitor_id": 12345,
"downtime_message": "Message",
"start": 1111,
"end": 2222,
"timezone": "UTC",
"rrule": "rrule",
"api_key": "an_api_key",
"app_key": "an_app_key",
}):
with set_module_args(
{
"id": 1212,
"monitor_tags": ["foo:bar"],
"scope": ["*"],
"monitor_id": 12345,
"downtime_message": "Message",
"start": 1111,
"end": 2222,
"timezone": "UTC",
"rrule": "rrule",
"api_key": "an_api_key",
"app_key": "an_app_key",
}
):
downtime = Downtime()
downtime.monitor_tags = ["foo:bar"]
downtime.scope = ["*"]
@@ -183,10 +184,7 @@ class TestDatadogDowntime(ModuleTestCase):
downtime.start = 1111
downtime.end = 2222
downtime.timezone = "UTC"
downtime.recurrence = DowntimeRecurrence(
rrule="rrule",
type="rrule"
)
downtime.recurrence = DowntimeRecurrence(rrule="rrule", type="rrule")
downtime_get = Downtime()
downtime_get.id = 1212
@@ -198,9 +196,7 @@ class TestDatadogDowntime(ModuleTestCase):
downtime_get.start = 1111
downtime_get.end = 2222
downtime_get.timezone = "UTC"
downtime_get.recurrence = DowntimeRecurrence(
rrule="rrule"
)
downtime_get.recurrence = DowntimeRecurrence(rrule="rrule")
update_downtime_mock = MagicMock(return_value=downtime_get)
get_downtime_mock = MagicMock(return_value=downtime_get)
@@ -210,28 +206,29 @@ class TestDatadogDowntime(ModuleTestCase):
with self.assertRaises(AnsibleExitJson) as result:
self.module.main()
self.assertFalse(result.exception.args[0]['changed'])
self.assertEqual(result.exception.args[0]['downtime']['id'], 1212)
self.assertFalse(result.exception.args[0]["changed"])
self.assertEqual(result.exception.args[0]["downtime"]["id"], 1212)
update_downtime_mock.assert_called_once_with(1212, downtime)
get_downtime_mock.assert_called_once_with(1212)
@patch("ansible_collections.community.general.plugins.modules.datadog_downtime.DowntimesApi")
def test_delete_downtime(self, downtimes_api_mock):
with set_module_args({
"id": 1212,
"state": "absent",
"api_key": "an_api_key",
"app_key": "an_app_key",
}):
with set_module_args(
{
"id": 1212,
"state": "absent",
"api_key": "an_api_key",
"app_key": "an_app_key",
}
):
cancel_downtime_mock = MagicMock()
downtimes_api_mock.return_value = MagicMock(
get_downtime=self.__downtime_with_id,
cancel_downtime=cancel_downtime_mock
get_downtime=self.__downtime_with_id, cancel_downtime=cancel_downtime_mock
)
with self.assertRaises(AnsibleExitJson) as result:
self.module.main()
self.assertTrue(result.exception.args[0]['changed'])
self.assertTrue(result.exception.args[0]["changed"])
cancel_downtime_mock.assert_called_once_with(1212)
def __downtime_with_id(self, id):