mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #22499 from rahulhan/states_http_unit_test
Adding states/http.py unit test cases
This commit is contained in:
commit
ae55fb4824
53
tests/unit/states/http_test.py
Normal file
53
tests/unit/states/http_test.py
Normal file
@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email:`Rahul Handay <rahulha@saltstack.com>`
|
||||
'''
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Salt Libs
|
||||
from salt.states import http
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from salttesting import skipIf, TestCase
|
||||
from salttesting.helpers import ensure_in_syspath
|
||||
from salttesting.mock import (
|
||||
NO_MOCK,
|
||||
NO_MOCK_REASON,
|
||||
MagicMock,
|
||||
patch
|
||||
)
|
||||
|
||||
ensure_in_syspath('../../')
|
||||
|
||||
http.__salt__ = {}
|
||||
http.__opts__ = {}
|
||||
|
||||
|
||||
@skipIf(NO_MOCK, NO_MOCK_REASON)
|
||||
class HttpTestCase(TestCase):
|
||||
'''
|
||||
Validate the HTTP state
|
||||
'''
|
||||
def test_query(self):
|
||||
'''
|
||||
Test to perform an HTTP query and statefully return the result
|
||||
'''
|
||||
ret = [{'changes': {},
|
||||
'comment': ' Either match text (match) or a '
|
||||
'status code (status) is required.', 'data': {},
|
||||
'name': 'salt', 'result': False},
|
||||
{'changes': {}, 'comment': '', 'data': True, 'name': 'salt',
|
||||
'result': None}]
|
||||
self.assertDictEqual(http.query("salt"), ret[0])
|
||||
|
||||
with patch.dict(http.__opts__, {'test': True}):
|
||||
mock = MagicMock(return_value=True)
|
||||
with patch.dict(http.__salt__, {'http.query': mock}):
|
||||
self.assertDictEqual(http.query("salt", "Dude", "stack"),
|
||||
ret[1])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests
|
||||
run_tests(HttpTestCase, needs_daemon=False)
|
Loading…
Reference in New Issue
Block a user