Skip to content

Commit

Permalink
Added simple test for Telegram returner
Browse files Browse the repository at this point in the history
  • Loading branch information
roaldnefs committed Oct 20, 2017
1 parent 1cd7843 commit f430e1e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/unit/returners/test_telegram_return.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Roald Nefs (info@roaldnefs.com)`
tests.unit.returners.telegram_return_test
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'''

# Import Python libs
from __future__ import absolute_import

# Import Salt Testing libs
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import NO_MOCK, NO_MOCK_REASON, MagicMock, patch

# Import salt libs
import salt.returners.telegram_return as telegram


@skipIf(NO_MOCK, NO_MOCK_REASON)
class TelegramReturnerTestCase(TestCase, LoaderModuleMockMixin):
'''
Test Telegram Returner
'''
def setup_loader_modules(self):
return {telegram: {}}

def test_returner(self):
'''
Test to see if the Telegram returner sends a message
'''
ret = {'id': '12345',
'fun': 'mytest.func',
'fun_args': 'myfunc args',
'jid': '54321',
'return': 'The room is on fire as shes fixing her hair'}
options = {'chat_id': '',
'token': ''}

class MockRequest(object):
"""
Mock of requests response
"""
def json(self):
return {'message_id': ''}

with patch('salt.returners.telegram_return._get_options',
MagicMock(return_value=options)), \
patch('salt.returners.telegram_return.requests.post',
MagicMock(return_value=MockRequest())):

self.assertTrue(telegram.returner(ret))

0 comments on commit f430e1e

Please sign in to comment.