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

@@ -10,7 +10,12 @@ from unittest.mock import patch
import pytest
from ansible_collections.community.general.plugins.modules import pagerduty_change
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import (
AnsibleExitJson,
AnsibleFailJson,
ModuleTestCase,
set_module_args,
)
class TestPagerDutyChangeModule(ModuleTestCase):
@@ -23,7 +28,7 @@ class TestPagerDutyChangeModule(ModuleTestCase):
@pytest.fixture
def fetch_url_mock(self, mocker):
return mocker.patch('ansible.module_utils.monitoring.pagerduty_change.fetch_url')
return mocker.patch("ansible.module_utils.monitoring.pagerduty_change.fetch_url")
def test_module_fail_when_required_args_missing(self):
with self.assertRaises(AnsibleFailJson):
@@ -31,56 +36,53 @@ class TestPagerDutyChangeModule(ModuleTestCase):
self.module.main()
def test_ensure_change_event_created_with_minimal_data(self):
with set_module_args({
'integration_key': 'test',
'summary': 'Testing'
}):
with patch.object(pagerduty_change, 'fetch_url') as fetch_url_mock:
with set_module_args({"integration_key": "test", "summary": "Testing"}):
with patch.object(pagerduty_change, "fetch_url") as fetch_url_mock:
fetch_url_mock.return_value = (None, {"status": 202})
with self.assertRaises(AnsibleExitJson):
self.module.main()
assert fetch_url_mock.call_count == 1
url = fetch_url_mock.call_args[0][1]
json_data = fetch_url_mock.call_args[1]['data']
json_data = fetch_url_mock.call_args[1]["data"]
data = json.loads(json_data)
assert url == 'https://events.pagerduty.com/v2/change/enqueue'
assert data['routing_key'] == 'test'
assert data['payload']['summary'] == 'Testing'
assert data['payload']['source'] == 'Ansible'
assert url == "https://events.pagerduty.com/v2/change/enqueue"
assert data["routing_key"] == "test"
assert data["payload"]["summary"] == "Testing"
assert data["payload"]["source"] == "Ansible"
def test_ensure_change_event_created_with_full_data(self):
with set_module_args({
'integration_key': 'test',
'summary': 'Testing',
'source': 'My Ansible Script',
'user': 'ansible',
'repo': 'github.com/ansible/ansible',
'revision': '8c67432',
'environment': 'production',
'link_url': 'https://pagerduty.com',
'link_text': 'PagerDuty'
}):
with patch.object(pagerduty_change, 'fetch_url') as fetch_url_mock:
with set_module_args(
{
"integration_key": "test",
"summary": "Testing",
"source": "My Ansible Script",
"user": "ansible",
"repo": "github.com/ansible/ansible",
"revision": "8c67432",
"environment": "production",
"link_url": "https://pagerduty.com",
"link_text": "PagerDuty",
}
):
with patch.object(pagerduty_change, "fetch_url") as fetch_url_mock:
fetch_url_mock.return_value = (None, {"status": 202})
with self.assertRaises(AnsibleExitJson):
self.module.main()
assert fetch_url_mock.call_count == 1
url = fetch_url_mock.call_args[0][1]
json_data = fetch_url_mock.call_args[1]['data']
json_data = fetch_url_mock.call_args[1]["data"]
data = json.loads(json_data)
assert url == 'https://events.pagerduty.com/v2/change/enqueue'
assert data['routing_key'] == 'test'
assert data['payload']['summary'] == 'Testing'
assert data['payload']['source'] == 'My Ansible Script'
assert data['payload']['custom_details']['user'] == 'ansible'
assert data['payload']['custom_details']['repo'] == 'github.com/ansible/ansible'
assert data['payload']['custom_details']['revision'] == '8c67432'
assert data['payload']['custom_details']['environment'] == 'production'
assert data['links'][0]['href'] == 'https://pagerduty.com'
assert data['links'][0]['text'] == 'PagerDuty'
assert url == "https://events.pagerduty.com/v2/change/enqueue"
assert data["routing_key"] == "test"
assert data["payload"]["summary"] == "Testing"
assert data["payload"]["source"] == "My Ansible Script"
assert data["payload"]["custom_details"]["user"] == "ansible"
assert data["payload"]["custom_details"]["repo"] == "github.com/ansible/ansible"
assert data["payload"]["custom_details"]["revision"] == "8c67432"
assert data["payload"]["custom_details"]["environment"] == "production"
assert data["links"][0]["href"] == "https://pagerduty.com"
assert data["links"][0]["text"] == "PagerDuty"