forked from saltstack/salt
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple test for Telegram returner
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |