migrate test_pagerduty to pytest

This commit is contained in:
Frode Gundersen 2022-12-07 21:32:25 +00:00
parent b84e72a51c
commit 7410c9a89c
No known key found for this signature in database
GPG key ID: DAB4C1C375D2EF45
2 changed files with 75 additions and 72 deletions

View file

@ -0,0 +1,75 @@
"""
:codeauthor: Rahul Handay <rahulha@saltstack.com>
Test cases for salt.modules.pagerduty
"""
import pytest
import salt.modules.pagerduty as pagerduty
import salt.utils.json
import salt.utils.pagerduty
from tests.support.mock import MagicMock, patch
@pytest.fixture
def configure_loader_modules():
return {pagerduty: {"__salt__": {"config.option": MagicMock(return_value=None)}}}
def test_list_services():
"""
Test for List services belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
assert pagerduty.list_services() == "A"
def test_list_incidents():
"""
Test for List incidents belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
assert pagerduty.list_incidents() == "A"
def test_list_users():
"""
Test for List users belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
assert pagerduty.list_users() == "A"
def test_list_schedules():
"""
Test for List schedules belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
assert pagerduty.list_schedules() == "A"
def test_list_windows():
"""
Test for List maintenance windows belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
assert pagerduty.list_windows() == "A"
def test_list_policies():
"""
Test for List escalation policies belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
assert pagerduty.list_policies() == "A"
def test_create_event():
"""
Test for Create an event in PagerDuty. Designed for use in states.
"""
with patch.object(salt.utils.json, "loads", return_value=["A"]):
with patch.object(salt.utils.pagerduty, "query", return_value="A"):
assert pagerduty.create_event() == ["A"]

View file

@ -1,72 +0,0 @@
"""
:codeauthor: Rahul Handay <rahulha@saltstack.com>
"""
import salt.modules.pagerduty as pagerduty
import salt.utils.json
import salt.utils.pagerduty
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import MagicMock, patch
from tests.support.unit import TestCase
class PagerdutyTestCase(TestCase, LoaderModuleMockMixin):
"""
Test cases for salt.modules.pagerduty
"""
def setup_loader_modules(self):
return {
pagerduty: {"__salt__": {"config.option": MagicMock(return_value=None)}}
}
def test_list_services(self):
"""
Test for List services belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
self.assertEqual(pagerduty.list_services(), "A")
def test_list_incidents(self):
"""
Test for List incidents belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
self.assertEqual(pagerduty.list_incidents(), "A")
def test_list_users(self):
"""
Test for List users belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
self.assertEqual(pagerduty.list_users(), "A")
def test_list_schedules(self):
"""
Test for List schedules belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
self.assertEqual(pagerduty.list_schedules(), "A")
def test_list_windows(self):
"""
Test for List maintenance windows belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
self.assertEqual(pagerduty.list_windows(), "A")
def test_list_policies(self):
"""
Test for List escalation policies belonging to this account
"""
with patch.object(salt.utils.pagerduty, "list_items", return_value="A"):
self.assertEqual(pagerduty.list_policies(), "A")
def test_create_event(self):
"""
Test for Create an event in PagerDuty. Designed for use in states.
"""
with patch.object(salt.utils.json, "loads", return_value=["A"]):
with patch.object(salt.utils.pagerduty, "query", return_value="A"):
self.assertListEqual(pagerduty.create_event(), ["A"])