2015-04-09 10:12:01 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
2018-05-28 21:13:12 +00:00
|
|
|
:codeauthor: Rahul Handay <rahulha@saltstack.com>
|
2015-04-09 10:12:01 +00:00
|
|
|
'''
|
|
|
|
# Import Python libs
|
2018-01-16 21:48:58 +00:00
|
|
|
from __future__ import absolute_import, print_function, unicode_literals
|
2015-04-09 10:12:01 +00:00
|
|
|
|
|
|
|
# Import Salt Libs
|
2017-03-21 17:15:36 +00:00
|
|
|
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
|
2017-02-27 13:58:07 +00:00
|
|
|
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])
|