salt/tests/unit/states/test_http.py

47 lines
1.4 KiB
Python
Raw Normal View History

2015-04-09 10:12:01 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: Rahul Handay <rahulha@saltstack.com>
2015-04-09 10:12:01 +00:00
'''
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
2015-04-09 10:12:01 +00:00
# Import Salt Libs
import salt.states.http as http
2015-04-09 10:12:01 +00:00
# Import Salt Testing Libs
2017-03-22 16:42:17 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import skipIf, TestCase
from tests.support.mock import (
2015-04-09 10:12:01 +00:00
NO_MOCK,
NO_MOCK_REASON,
MagicMock,
patch
)
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-22 16:42:17 +00:00
class HttpTestCase(TestCase, LoaderModuleMockMixin):
2015-04-09 10:12:01 +00:00
'''
Validate the HTTP state
'''
2017-03-22 16:42:17 +00:00
def setup_loader_modules(self):
return {http: {}}
2015-04-09 10:12:01 +00:00
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},
2016-01-22 17:54:25 +00:00
{'changes': {}, 'comment': ' (TEST MODE)', 'data': True, 'name': 'salt',
2015-04-09 10:12:01 +00:00
'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])