mirror of
https://github.com/ansible/awx.git
synced 2026-01-11 01:57:35 -03:30
Adding unit test for no header response
This commit is contained in:
parent
aad432aaa3
commit
b9758f5c1a
@ -24,6 +24,11 @@ def getAWXheader(self, header_name, default):
|
||||
return mock_headers.get(header_name, default)
|
||||
|
||||
|
||||
def getNoheader(self, header_name, default):
|
||||
mock_headers = {}
|
||||
return mock_headers.get(header_name, default)
|
||||
|
||||
|
||||
def read(self):
|
||||
return json.dumps({})
|
||||
|
||||
@ -48,6 +53,14 @@ def mock_awx_ping_response(self, method, url, **kwargs):
|
||||
return r
|
||||
|
||||
|
||||
def mock_no_ping_response(self, method, url, **kwargs):
|
||||
r = Response()
|
||||
r.getheader = getNoheader.__get__(r)
|
||||
r.read = read.__get__(r)
|
||||
r.status = status.__get__(r)
|
||||
return r
|
||||
|
||||
|
||||
def test_version_warning(collection_import, silence_warning):
|
||||
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
||||
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
||||
@ -63,6 +76,21 @@ def test_version_warning(collection_import, silence_warning):
|
||||
)
|
||||
|
||||
|
||||
def test_no_version_warning(collection_import, silence_warning):
|
||||
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
||||
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
||||
testargs = ['module_file2.py', json.dumps(cli_data)]
|
||||
with mock.patch.object(sys, 'argv', testargs):
|
||||
with mock.patch('ansible.module_utils.urls.Request.open', new=mock_no_ping_response):
|
||||
my_module = ControllerAPIModule(argument_spec=dict())
|
||||
my_module._COLLECTION_VERSION = "2.0.0"
|
||||
my_module._COLLECTION_TYPE = "awx"
|
||||
my_module.get_endpoint('ping')
|
||||
silence_warning.assert_called_once_with(
|
||||
'You are using the {0} version of this collection but connecting to a controller that did not return a version'.format(my_module._COLLECTION_VERSION)
|
||||
)
|
||||
|
||||
|
||||
def test_version_warning_strictness_awx(collection_import, silence_warning):
|
||||
ControllerAPIModule = collection_import('plugins.module_utils.controller_api').ControllerAPIModule
|
||||
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user