mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
migrate test_google_chat to pytest
This commit is contained in:
parent
11b3f724d3
commit
36e2078589
2 changed files with 47 additions and 49 deletions
47
tests/pytests/unit/modules/test_google_chat.py
Normal file
47
tests/pytests/unit/modules/test_google_chat.py
Normal 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")
|
|
@ -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"))
|
Loading…
Add table
Reference in a new issue