migrate test_google_chat to pytest

This commit is contained in:
Frode Gundersen 2023-01-05 20:58:35 +00:00
parent 11b3f724d3
commit 36e2078589
No known key found for this signature in database
GPG key ID: DAB4C1C375D2EF45
2 changed files with 47 additions and 49 deletions

View file

@ -0,0 +1,47 @@
"""
Test the Google Chat Execution module.
"""
import pytest
import salt.modules.google_chat as gchat
from tests.support.mock import patch
@pytest.fixture
def configure_loader_modules():
return {gchat: {}}
def mocked_http_query(url, method, **kwargs): # pylint: disable=unused-argument
"""
Mocked data for test_send_message_success
"""
return {"status": 200, "dict": None}
def mocked_http_query_failure(url, method, **kwargs): # pylint: disable=unused-argument
"""
Mocked data for test_send_message_failure
"""
return {"status": 522, "dict": None}
def test_send_message_success():
"""
Testing a successful message
"""
with patch.dict(
gchat.__utils__, {"http.query": mocked_http_query}
): # pylint: disable=no-member
assert gchat.send_message("https://example.com", "Yupiii")
def test_send_message_failure():
"""
Testing a failed message
"""
with patch.dict(
gchat.__utils__, {"http.query": mocked_http_query_failure}
): # pylint: disable=no-member
assert not gchat.send_message("https://example.com", "Yupiii")

View file

@ -1,49 +0,0 @@
"""
Test the Google Chat Execution module.
"""
import salt.modules.google_chat as gchat
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.mock import patch
from tests.support.unit import TestCase
def mocked_http_query(url, method, **kwargs): # pylint: disable=unused-argument
"""
Mocked data for test_send_message_success
"""
return {"status": 200, "dict": None}
def mocked_http_query_failure(url, method, **kwargs): # pylint: disable=unused-argument
"""
Mocked data for test_send_message_failure
"""
return {"status": 522, "dict": None}
class TestModulesCfutils(TestCase, LoaderModuleMockMixin):
"""
Test cases for salt.modules.google_chat
"""
def setup_loader_modules(self):
return {gchat: {}}
def test_send_message_success(self):
"""
Testing a successful message
"""
with patch.dict(
gchat.__utils__, {"http.query": mocked_http_query}
): # pylint: disable=no-member
self.assertTrue(gchat.send_message("https://example.com", "Yupiii"))
def test_send_message_failure(self):
"""
Testing a failed message
"""
with patch.dict(
gchat.__utils__, {"http.query": mocked_http_query_failure}
): # pylint: disable=no-member
self.assertFalse(gchat.send_message("https://example.com", "Yupiii"))