mirror of
https://github.com/ansible/awx.git
synced 2026-05-15 13:27:40 -02:30
Fix up unit tests (no more double mocking)
This commit is contained in:
@@ -33,15 +33,14 @@ def test_version_warning(collection_import, silence_warning):
|
|||||||
TowerModule = collection_import('plugins.module_utils.tower_api').TowerModule
|
TowerModule = collection_import('plugins.module_utils.tower_api').TowerModule
|
||||||
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
||||||
testargs = ['module_file2.py', json.dumps(cli_data)]
|
testargs = ['module_file2.py', json.dumps(cli_data)]
|
||||||
with mock.patch('ansible.module_utils.basic.AnsibleModule.warn') as mock_warn:
|
with mock.patch.object(sys, 'argv', testargs):
|
||||||
with mock.patch.object(sys, 'argv', testargs):
|
with mock.patch('ansible.module_utils.urls.Request.open', new=mock_ping_response):
|
||||||
with mock.patch('ansible.module_utils.urls.Request.open', new=mock_ping_response):
|
my_module = TowerModule(argument_spec=dict())
|
||||||
my_module = TowerModule(argument_spec=dict())
|
my_module._COLLECTION_VERSION = "1.0.0"
|
||||||
my_module._COLLECTION_VERSION = "1.0.0"
|
my_module._COLLECTION_TYPE = "not-junk"
|
||||||
my_module._COLLECTION_TYPE = "not-junk"
|
my_module.collection_to_version['not-junk'] = 'not-junk'
|
||||||
my_module.collection_to_version['not-junk'] = 'not-junk'
|
my_module.get_endpoint('ping')
|
||||||
my_module.get_endpoint('ping')
|
silence_warning.assert_called_once_with(
|
||||||
mock_warn.assert_called_once_with(
|
|
||||||
'You are running collection version 1.0.0 but connecting to tower version 1.2.3'
|
'You are running collection version 1.0.0 but connecting to tower version 1.2.3'
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -50,20 +49,19 @@ def test_type_warning(collection_import, silence_warning):
|
|||||||
TowerModule = collection_import('plugins.module_utils.tower_api').TowerModule
|
TowerModule = collection_import('plugins.module_utils.tower_api').TowerModule
|
||||||
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
cli_data = {'ANSIBLE_MODULE_ARGS': {}}
|
||||||
testargs = ['module_file2.py', json.dumps(cli_data)]
|
testargs = ['module_file2.py', json.dumps(cli_data)]
|
||||||
with mock.patch('ansible.module_utils.basic.AnsibleModule.warn') as mock_warn:
|
with mock.patch.object(sys, 'argv', testargs):
|
||||||
with mock.patch.object(sys, 'argv', testargs):
|
with mock.patch('ansible.module_utils.urls.Request.open', new=mock_ping_response):
|
||||||
with mock.patch('ansible.module_utils.urls.Request.open', new=mock_ping_response):
|
my_module = TowerModule(argument_spec={})
|
||||||
my_module = TowerModule(argument_spec={})
|
my_module._COLLECTION_VERSION = "1.2.3"
|
||||||
my_module._COLLECTION_VERSION = "1.2.3"
|
my_module._COLLECTION_TYPE = "junk"
|
||||||
my_module._COLLECTION_TYPE = "junk"
|
my_module.collection_to_version['junk'] = 'junk'
|
||||||
my_module.collection_to_version['junk'] = 'junk'
|
my_module.get_endpoint('ping')
|
||||||
my_module.get_endpoint('ping')
|
silence_warning.assert_called_once_with(
|
||||||
mock_warn.assert_called_once_with(
|
|
||||||
'You are using the junk version of this collection but connecting to not-junk'
|
'You are using the junk version of this collection but connecting to not-junk'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_duplicate_config(collection_import):
|
def test_duplicate_config(collection_import, silence_warning):
|
||||||
# imports done here because of PATH issues unique to this test suite
|
# imports done here because of PATH issues unique to this test suite
|
||||||
TowerModule = collection_import('plugins.module_utils.tower_api').TowerModule
|
TowerModule = collection_import('plugins.module_utils.tower_api').TowerModule
|
||||||
data = {
|
data = {
|
||||||
@@ -82,14 +80,13 @@ def test_duplicate_config(collection_import):
|
|||||||
|
|
||||||
cli_data = {'ANSIBLE_MODULE_ARGS': data}
|
cli_data = {'ANSIBLE_MODULE_ARGS': data}
|
||||||
testargs = ['module_file.py', json.dumps(cli_data)]
|
testargs = ['module_file.py', json.dumps(cli_data)]
|
||||||
with mock.patch('ansible.module_utils.basic.AnsibleModule.warn') as mock_warn:
|
with mock.patch.object(sys, 'argv', testargs):
|
||||||
with mock.patch.object(sys, 'argv', testargs):
|
argument_spec = dict(
|
||||||
argument_spec = dict(
|
name=dict(required=True),
|
||||||
name=dict(required=True),
|
zig=dict(type='str'),
|
||||||
zig=dict(type='str'),
|
)
|
||||||
)
|
DuplicateTestTowerModule(argument_spec=argument_spec)
|
||||||
DuplicateTestTowerModule(argument_spec=argument_spec)
|
silence_warning.assert_called_once_with(
|
||||||
mock_warn.assert_called_once_with(
|
|
||||||
'The parameter(s) tower_username were provided at the same time as '
|
'The parameter(s) tower_username were provided at the same time as '
|
||||||
'tower_config_file. Precedence may be unstable, '
|
'tower_config_file. Precedence may be unstable, '
|
||||||
'we suggest either using config file or params.'
|
'we suggest either using config file or params.'
|
||||||
|
|||||||
@@ -9,17 +9,16 @@ from awx.main.models import Project
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_create_project(run_module, admin_user, organization):
|
def test_create_project(run_module, admin_user, organization, silence_warning):
|
||||||
with mock.patch('ansible.module_utils.basic.AnsibleModule.warn') as mock_warn:
|
result = run_module('tower_project', dict(
|
||||||
result = run_module('tower_project', dict(
|
name='foo',
|
||||||
name='foo',
|
organization=organization.name,
|
||||||
organization=organization.name,
|
scm_type='git',
|
||||||
scm_type='git',
|
scm_url='https://foo.invalid',
|
||||||
scm_url='https://foo.invalid',
|
wait=False,
|
||||||
wait=False,
|
scm_update_cache_timeout=5
|
||||||
scm_update_cache_timeout=5
|
), admin_user)
|
||||||
), admin_user)
|
silence_warning.assert_has_calls(
|
||||||
mock_warn.assert_has_calls(
|
|
||||||
[mock.call('scm_update_cache_timeout will be ignored since scm_update_on_launch '
|
[mock.call('scm_update_cache_timeout will be ignored since scm_update_on_launch '
|
||||||
'was not set to true')])
|
'was not set to true')])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user