You've already forked community.general
mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-30 18:43:09 +03:00
Unflatmap community.general (#5461)
* Move files. * Update imports and references. * Move wrongly placed files. * Reverse redirects, deprecate long → short name redirects. * Simplify contribution guidelines for new modules. * Rewrite BOTMETA. * Add changelog fragment. * Fix ignore.txt files.
This commit is contained in:
46
tests/unit/plugins/modules/test_pagerduty_alert.py
Normal file
46
tests/unit/plugins/modules/test_pagerduty_alert.py
Normal file
@ -0,0 +1,46 @@
|
||||
# Copyright (c) Ansible project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible_collections.community.general.tests.unit.compat import unittest
|
||||
from ansible_collections.community.general.plugins.modules import pagerduty_alert
|
||||
|
||||
|
||||
class PagerDutyAlertsTest(unittest.TestCase):
|
||||
def _assert_incident_api(self, module, url, method, headers):
|
||||
self.assertTrue('https://api.pagerduty.com/incidents' in url, 'url must contain REST API v2 network path')
|
||||
self.assertTrue('service_ids%5B%5D=service_id' in url, 'url must contain service id to filter incidents')
|
||||
self.assertTrue('sort_by=incident_number%3Adesc' in url, 'url should contain sorting parameter')
|
||||
self.assertTrue('time_zone=UTC' in url, 'url should contain time zone parameter')
|
||||
return Response(), {'status': 200}
|
||||
|
||||
def _assert_compatibility_header(self, module, url, method, headers):
|
||||
self.assertDictContainsSubset(
|
||||
{'Accept': 'application/vnd.pagerduty+json;version=2'},
|
||||
headers,
|
||||
'Accept:application/vnd.pagerduty+json;version=2 HTTP header not found'
|
||||
)
|
||||
return Response(), {'status': 200}
|
||||
|
||||
def _assert_incident_key(self, module, url, method, headers):
|
||||
self.assertTrue('incident_key=incident_key_value' in url, 'url must contain incident key')
|
||||
return Response(), {'status': 200}
|
||||
|
||||
def test_incident_url(self):
|
||||
pagerduty_alert.check(None, 'name', 'state', 'service_id', 'integration_key', 'api_key', http_call=self._assert_incident_api)
|
||||
|
||||
def test_compatibility_header(self):
|
||||
pagerduty_alert.check(None, 'name', 'state', 'service_id', 'integration_key', 'api_key', http_call=self._assert_compatibility_header)
|
||||
|
||||
def test_incident_key_in_url_when_it_is_given(self):
|
||||
pagerduty_alert.check(
|
||||
None, 'name', 'state', 'service_id', 'integration_key', 'api_key', incident_key='incident_key_value', http_call=self._assert_incident_key
|
||||
)
|
||||
|
||||
|
||||
class Response(object):
|
||||
def read(self):
|
||||
return '{"incidents":[{"id": "incident_id", "status": "triggered"}]}'
|
Reference in New Issue
Block a user