salt/tests/unit/modules/test_google_chat.py
Luke Overend 969d7d68fc
Add new google_chat module
To send a message directly to google chat via the api (not via a bot)
you need to configure a webhook and post directly to that webhook url.
2018-08-06 13:37:18 +01:00

53 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
'''
Test the Google Chat Execution module.
'''
from __future__ import absolute_import, print_function, unicode_literals
# Import Salt Testing libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, patch
# Import Salt Libs
import salt.modules.google_chat as 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}
@skipIf(NO_MOCK, NO_MOCK_REASON)
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'))