Clean up unit tests to assist with migration. (#67875)

* Split out cache plugin unit tests.

* Rename unit tests to match code under test.

* Relocate unit test code to match code under test.

* Another rename.

* Update sanity ignores.
pull/67878/head
Matt Clay 4 years ago committed by GitHub
parent 3c9747ba2f
commit 04666c9fa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -8297,6 +8297,10 @@ test/units/contrib/inventory/test_vmware_inventory.py future-import-boilerplate
test/units/contrib/inventory/test_vmware_inventory.py metaclass-boilerplate
test/units/contrib/inventory/test_vmware_inventory.py pylint:blacklisted-name
test/units/executor/test_play_iterator.py pylint:blacklisted-name
test/units/inventory/test_group.py future-import-boilerplate
test/units/inventory/test_group.py metaclass-boilerplate
test/units/inventory/test_host.py future-import-boilerplate
test/units/inventory/test_host.py metaclass-boilerplate
test/units/mock/path.py future-import-boilerplate
test/units/mock/path.py metaclass-boilerplate
test/units/mock/yaml_helper.py future-import-boilerplate
@ -8361,6 +8365,8 @@ test/units/module_utils/network/ftd/test_fdm_swagger_with_real_data.py future-im
test/units/module_utils/network/ftd/test_fdm_swagger_with_real_data.py metaclass-boilerplate
test/units/module_utils/network/ftd/test_upsert_functionality.py future-import-boilerplate
test/units/module_utils/network/ftd/test_upsert_functionality.py metaclass-boilerplate
test/units/module_utils/network/netscaler/test_netscaler.py future-import-boilerplate
test/units/module_utils/network/netscaler/test_netscaler.py metaclass-boilerplate
test/units/module_utils/network/nso/test_nso.py metaclass-boilerplate
test/units/module_utils/parsing/test_convert_bool.py future-import-boilerplate
test/units/module_utils/postgresql/test_postgres.py future-import-boilerplate
@ -8416,8 +8422,8 @@ test/units/modules/cloud/xenserver/FakeXenAPI.py metaclass-boilerplate
test/units/modules/conftest.py future-import-boilerplate
test/units/modules/conftest.py metaclass-boilerplate
test/units/modules/files/test_copy.py future-import-boilerplate
test/units/modules/messaging/rabbitmq/test_rabbimq_user.py future-import-boilerplate
test/units/modules/messaging/rabbitmq/test_rabbimq_user.py metaclass-boilerplate
test/units/modules/messaging/rabbitmq/test_rabbitmq_user.py future-import-boilerplate
test/units/modules/messaging/rabbitmq/test_rabbitmq_user.py metaclass-boilerplate
test/units/modules/monitoring/test_circonus_annotation.py future-import-boilerplate
test/units/modules/monitoring/test_circonus_annotation.py metaclass-boilerplate
test/units/modules/monitoring/test_icinga2_feature.py future-import-boilerplate
@ -8468,8 +8474,6 @@ test/units/modules/network/netscaler/test_netscaler_lb_monitor.py future-import-
test/units/modules/network/netscaler/test_netscaler_lb_monitor.py metaclass-boilerplate
test/units/modules/network/netscaler/test_netscaler_lb_vserver.py future-import-boilerplate
test/units/modules/network/netscaler/test_netscaler_lb_vserver.py metaclass-boilerplate
test/units/modules/network/netscaler/test_netscaler_module_utils.py future-import-boilerplate
test/units/modules/network/netscaler/test_netscaler_module_utils.py metaclass-boilerplate
test/units/modules/network/netscaler/test_netscaler_nitro_request.py future-import-boilerplate
test/units/modules/network/netscaler/test_netscaler_nitro_request.py metaclass-boilerplate
test/units/modules/network/netscaler/test_netscaler_save_config.py future-import-boilerplate
@ -8707,8 +8711,8 @@ test/units/modules/system/test_java_keystore.py metaclass-boilerplate
test/units/modules/system/test_known_hosts.py future-import-boilerplate
test/units/modules/system/test_known_hosts.py metaclass-boilerplate
test/units/modules/system/test_known_hosts.py pylint:ansible-bad-function
test/units/modules/system/test_linux_mountinfo.py future-import-boilerplate
test/units/modules/system/test_linux_mountinfo.py metaclass-boilerplate
test/units/modules/system/test_mount.py future-import-boilerplate
test/units/modules/system/test_mount.py metaclass-boilerplate
test/units/modules/system/test_pamd.py metaclass-boilerplate
test/units/modules/system/test_parted.py future-import-boilerplate
test/units/modules/system/test_systemd.py future-import-boilerplate
@ -8735,10 +8739,6 @@ test/units/plugins/httpapi/test_ftd.py future-import-boilerplate
test/units/plugins/httpapi/test_ftd.py metaclass-boilerplate
test/units/plugins/inventory/test_constructed.py future-import-boilerplate
test/units/plugins/inventory/test_constructed.py metaclass-boilerplate
test/units/plugins/inventory/test_group.py future-import-boilerplate
test/units/plugins/inventory/test_group.py metaclass-boilerplate
test/units/plugins/inventory/test_host.py future-import-boilerplate
test/units/plugins/inventory/test_host.py metaclass-boilerplate
test/units/plugins/loader_fixtures/import_fixture.py future-import-boilerplate
test/units/plugins/shell/test_cmd.py future-import-boilerplate
test/units/plugins/shell/test_cmd.py metaclass-boilerplate

@ -94,3 +94,156 @@ class TestNxosIPInterfaceModule(TestNxosModule):
def test_nxos_pim_interface_ip_absent(self):
set_module_args(dict(interface='eth2/1', state='absent'))
self.execute_module(changed=False, commands=[])
class TestNxosPimInterfaceBfdModule(TestNxosModule):
module = nxos_pim_interface
def setUp(self):
super(TestNxosPimInterfaceBfdModule, self).setUp()
self.mock_get_interface_mode = patch('ansible.modules.network.nxos.nxos_pim_interface.get_interface_mode')
self.get_interface_mode = self.mock_get_interface_mode.start()
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_pim_interface.get_config')
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_pim_interface.load_config')
self.load_config = self.mock_load_config.start()
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_pim_interface.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestNxosPimInterfaceBfdModule, self).tearDown()
self.mock_get_interface_mode.stop()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None, device=''):
self.load_config.return_value = None
def test_bfd_1(self):
# default (None) -> enable
self.get_config.return_value = None
set_module_args(dict(interface='eth2/1', bfd='enable'))
self.execute_module(
changed=True,
commands=[
'interface eth2/1',
'ip pim bfd-instance',
])
# default (None) -> disable
set_module_args(dict(interface='eth2/1', bfd='disable'))
self.execute_module(
changed=True,
commands=[
'interface eth2/1',
'ip pim bfd-instance disable',
])
# default (None) -> default (None) (idempotence)
set_module_args(dict(interface='eth2/1', bfd='default'))
self.execute_module(changed=False,)
# default (None) -> interface state 'default'
set_module_args(dict(interface='Ethernet9/3', state='default'))
self.execute_module(changed=False,)
# default (None) -> interface state 'absent'
set_module_args(dict(interface='Ethernet9/3', state='absent'))
self.execute_module(changed=False,)
def test_bfd_2(self):
# From disable
self.get_config.return_value = '''
interface Ethernet9/2
ip pim bfd-instance disable
'''
# disable -> enable
set_module_args(dict(interface='Ethernet9/2', bfd='enable'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/2',
'ip pim bfd-instance',
])
# disable -> disable (idempotence)
set_module_args(dict(interface='Ethernet9/2', bfd='disable'))
self.execute_module(changed=False,)
# disable -> default (None)
set_module_args(dict(interface='Ethernet9/2', bfd='default'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/2',
'no ip pim bfd-instance',
])
# disable -> interface state 'default'
set_module_args(dict(interface='Ethernet9/3', state='default'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])
# disable -> interface state 'absent'
set_module_args(dict(interface='Ethernet9/3', state='absent'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])
def test_bfd_3(self):
# From enable
self.get_config.return_value = '''
interface Ethernet9/2
ip pim bfd-instance
'''
# enable -> disabled
set_module_args(dict(interface='Ethernet9/3', bfd='disable'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'ip pim bfd-instance disable',
])
# enable -> enable (idempotence)
set_module_args(dict(interface='Ethernet9/3', bfd='enable'))
self.execute_module(changed=False,)
# enable -> default (None)
set_module_args(dict(interface='Ethernet9/3', bfd='default'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])
# enable -> interface state 'default'
set_module_args(dict(interface='Ethernet9/3', state='default'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])
# enable -> interface state 'absent'
set_module_args(dict(interface='Ethernet9/3', state='absent'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])

@ -1,177 +0,0 @@
# (c) 2019 Red Hat Inc.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from units.compat.mock import patch
from ansible.modules.network.nxos import nxos_pim_interface
from .nxos_module import TestNxosModule, set_module_args
class TestNxosPimInterfaceBfdModule(TestNxosModule):
module = nxos_pim_interface
def setUp(self):
super(TestNxosPimInterfaceBfdModule, self).setUp()
self.mock_get_interface_mode = patch('ansible.modules.network.nxos.nxos_pim_interface.get_interface_mode')
self.get_interface_mode = self.mock_get_interface_mode.start()
self.mock_get_config = patch('ansible.modules.network.nxos.nxos_pim_interface.get_config')
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch('ansible.modules.network.nxos.nxos_pim_interface.load_config')
self.load_config = self.mock_load_config.start()
self.mock_run_commands = patch('ansible.modules.network.nxos.nxos_pim_interface.run_commands')
self.run_commands = self.mock_run_commands.start()
def tearDown(self):
super(TestNxosPimInterfaceBfdModule, self).tearDown()
self.mock_get_interface_mode.stop()
self.mock_get_config.stop()
self.mock_load_config.stop()
self.mock_run_commands.stop()
def load_fixtures(self, commands=None, device=''):
self.load_config.return_value = None
def test_bfd_1(self):
# default (None) -> enable
self.get_config.return_value = None
set_module_args(dict(interface='eth2/1', bfd='enable'))
self.execute_module(
changed=True,
commands=[
'interface eth2/1',
'ip pim bfd-instance',
])
# default (None) -> disable
set_module_args(dict(interface='eth2/1', bfd='disable'))
self.execute_module(
changed=True,
commands=[
'interface eth2/1',
'ip pim bfd-instance disable',
])
# default (None) -> default (None) (idempotence)
set_module_args(dict(interface='eth2/1', bfd='default'))
self.execute_module(changed=False,)
# default (None) -> interface state 'default'
set_module_args(dict(interface='Ethernet9/3', state='default'))
self.execute_module(changed=False,)
# default (None) -> interface state 'absent'
set_module_args(dict(interface='Ethernet9/3', state='absent'))
self.execute_module(changed=False,)
def test_bfd_2(self):
# From disable
self.get_config.return_value = '''
interface Ethernet9/2
ip pim bfd-instance disable
'''
# disable -> enable
set_module_args(dict(interface='Ethernet9/2', bfd='enable'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/2',
'ip pim bfd-instance',
])
# disable -> disable (idempotence)
set_module_args(dict(interface='Ethernet9/2', bfd='disable'))
self.execute_module(changed=False,)
# disable -> default (None)
set_module_args(dict(interface='Ethernet9/2', bfd='default'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/2',
'no ip pim bfd-instance',
])
# disable -> interface state 'default'
set_module_args(dict(interface='Ethernet9/3', state='default'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])
# disable -> interface state 'absent'
set_module_args(dict(interface='Ethernet9/3', state='absent'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])
def test_bfd_3(self):
# From enable
self.get_config.return_value = '''
interface Ethernet9/2
ip pim bfd-instance
'''
# enable -> disabled
set_module_args(dict(interface='Ethernet9/3', bfd='disable'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'ip pim bfd-instance disable',
])
# enable -> enable (idempotence)
set_module_args(dict(interface='Ethernet9/3', bfd='enable'))
self.execute_module(changed=False,)
# enable -> default (None)
set_module_args(dict(interface='Ethernet9/3', bfd='default'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])
# enable -> interface state 'default'
set_module_args(dict(interface='Ethernet9/3', state='default'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])
# enable -> interface state 'absent'
set_module_args(dict(interface='Ethernet9/3', state='absent'))
self.execute_module(
changed=True,
commands=[
'interface Ethernet9/3',
'no ip pim bfd-instance',
])

@ -26,24 +26,6 @@ from ansible.plugins.cache.base import BaseCacheModule
from ansible.plugins.cache.memory import CacheModule as MemoryCache
from ansible.plugins.loader import cache_loader
HAVE_MEMCACHED = True
try:
import memcache
except ImportError:
HAVE_MEMCACHED = False
else:
# Use an else so that the only reason we skip this is for lack of
# memcached, not errors importing the plugin
from ansible.plugins.cache.memcached import CacheModule as MemcachedCache
HAVE_REDIS = True
try:
import redis
except ImportError:
HAVE_REDIS = False
else:
from ansible.plugins.cache.redis import CacheModule as RedisCache
import pytest
@ -178,25 +160,8 @@ class TestAbstractClass(unittest.TestCase):
self.assertIsInstance(CacheModule3(), CacheModule3)
@unittest.skipUnless(HAVE_MEMCACHED, 'python-memcached module not installed')
def test_memcached_cachemodule(self):
self.assertIsInstance(MemcachedCache(), MemcachedCache)
@unittest.skipUnless(HAVE_MEMCACHED, 'python-memcached module not installed')
def test_memcached_cachemodule_with_loader(self):
self.assertIsInstance(cache_loader.get('memcached'), MemcachedCache)
def test_memory_cachemodule(self):
self.assertIsInstance(MemoryCache(), MemoryCache)
def test_memory_cachemodule_with_loader(self):
self.assertIsInstance(cache_loader.get('memory'), MemoryCache)
@unittest.skipUnless(HAVE_REDIS, 'Redis python module not installed')
def test_redis_cachemodule(self):
self.assertIsInstance(RedisCache(), RedisCache)
@unittest.skipUnless(HAVE_REDIS, 'Redis python module not installed')
def test_redis_cachemodule_with_loader(self):
# The _uri option is required for the redis plugin
self.assertIsInstance(cache_loader.get('redis', **{'_uri': '127.0.0.1:6379:1'}), RedisCache)

@ -0,0 +1,35 @@
# (c) 2012-2015, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import pytest
pytest.importorskip('memcache')
from ansible.plugins.loader import cache_loader
from ansible.plugins.cache.memcached import CacheModule as MemcachedCache
def test_memcached_cachemodule():
assert isinstance(MemcachedCache(), MemcachedCache)
def test_memcached_cachemodule_with_loader():
assert isinstance(cache_loader.get('memcached'), MemcachedCache)

@ -0,0 +1,36 @@
# (c) 2012-2015, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import pytest
pytest.importorskip('redis')
from ansible.plugins.loader import cache_loader
from ansible.plugins.cache.redis import CacheModule as RedisCache
def test_redis_cachemodule():
assert isinstance(RedisCache(), RedisCache)
def test_redis_cachemodule_with_loader():
# The _uri option is required for the redis plugin
assert isinstance(cache_loader.get('redis', **{'_uri': '127.0.0.1:6379:1'}), RedisCache)
Loading…
Cancel
Save