mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-15 17:40:50 -07:00
Making the switch to v2
This commit is contained in:
parent
8cf4452d48
commit
ce3ef7f4c1
486 changed files with 7948 additions and 9070 deletions
21
test/units/plugins/__init__.py
Normal file
21
test/units/plugins/__init__.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# (c) 2012-2014, 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
|
||||
|
100
test/units/plugins/test_cache.py
Normal file
100
test/units/plugins/test_cache.py
Normal file
|
@ -0,0 +1,100 @@
|
|||
# (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
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.plugins.cache.base import BaseCacheModule
|
||||
from ansible.plugins.cache.memory import CacheModule as MemoryCache
|
||||
|
||||
HAVE_MEMCACHED = True
|
||||
try:
|
||||
import memcached
|
||||
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
|
||||
|
||||
|
||||
class TestAbstractClass(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_subclass_error(self):
|
||||
class CacheModule1(BaseCacheModule):
|
||||
pass
|
||||
with self.assertRaises(TypeError):
|
||||
CacheModule1()
|
||||
|
||||
class CacheModule2(BaseCacheModule):
|
||||
def get(self, key):
|
||||
super(CacheModule2, self).get(key)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
CacheModule2()
|
||||
|
||||
def test_subclass_success(self):
|
||||
class CacheModule3(BaseCacheModule):
|
||||
def get(self, key):
|
||||
super(CacheModule3, self).get(key)
|
||||
|
||||
def set(self, key, value):
|
||||
super(CacheModule3, self).set(key, value)
|
||||
|
||||
def keys(self):
|
||||
super(CacheModule3, self).keys()
|
||||
|
||||
def contains(self, key):
|
||||
super(CacheModule3, self).contains(key)
|
||||
|
||||
def delete(self, key):
|
||||
super(CacheModule3, self).delete(key)
|
||||
|
||||
def flush(self):
|
||||
super(CacheModule3, self).flush()
|
||||
|
||||
def copy(self):
|
||||
super(CacheModule3, self).copy()
|
||||
|
||||
self.assertIsInstance(CacheModule3(), CacheModule3)
|
||||
|
||||
@unittest.skipUnless(HAVE_MEMCACHED, 'python-memcached module not installed')
|
||||
def test_memcached_cachemodule(self):
|
||||
self.assertIsInstance(MemcachedCache(), MemcachedCache)
|
||||
|
||||
def test_memory_cachemodule(self):
|
||||
self.assertIsInstance(MemoryCache(), MemoryCache)
|
||||
|
||||
@unittest.skipUnless(HAVE_REDIS, 'Redis pyhton module not installed')
|
||||
def test_redis_cachemodule(self):
|
||||
self.assertIsInstance(RedisCache(), RedisCache)
|
102
test/units/plugins/test_connection.py
Normal file
102
test/units/plugins/test_connection.py
Normal file
|
@ -0,0 +1,102 @@
|
|||
# (c) 2015, Toshio Kuratomi <tkuratomi@ansible.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
|
||||
|
||||
from six import StringIO
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.executor.connection_info import ConnectionInformation
|
||||
|
||||
from ansible.plugins.connections import ConnectionBase
|
||||
#from ansible.plugins.connections.accelerate import Connection as AccelerateConnection
|
||||
#from ansible.plugins.connections.chroot import Connection as ChrootConnection
|
||||
#from ansible.plugins.connections.funcd import Connection as FuncdConnection
|
||||
#from ansible.plugins.connections.jail import Connection as JailConnection
|
||||
#from ansible.plugins.connections.libvirt_lxc import Connection as LibvirtLXCConnection
|
||||
from ansible.plugins.connections.local import Connection as LocalConnection
|
||||
from ansible.plugins.connections.paramiko_ssh import Connection as ParamikoConnection
|
||||
from ansible.plugins.connections.ssh import Connection as SSHConnection
|
||||
#from ansible.plugins.connections.winrm import Connection as WinRmConnection
|
||||
|
||||
class TestConnectionBaseClass(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.conn_info = ConnectionInformation()
|
||||
self.in_stream = StringIO()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_subclass_error(self):
|
||||
class ConnectionModule1(ConnectionBase):
|
||||
pass
|
||||
with self.assertRaises(TypeError):
|
||||
ConnectionModule1()
|
||||
|
||||
class ConnectionModule2(ConnectionBase):
|
||||
def get(self, key):
|
||||
super(ConnectionModule2, self).get(key)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
ConnectionModule2()
|
||||
|
||||
def test_subclass_success(self):
|
||||
class ConnectionModule3(ConnectionBase):
|
||||
@property
|
||||
def transport(self):
|
||||
pass
|
||||
def _connect(self):
|
||||
pass
|
||||
def exec_command(self):
|
||||
pass
|
||||
def put_file(self):
|
||||
pass
|
||||
def fetch_file(self):
|
||||
pass
|
||||
def close(self):
|
||||
pass
|
||||
self.assertIsInstance(ConnectionModule3(self.conn_info, self.in_stream), ConnectionModule3)
|
||||
|
||||
# def test_accelerate_connection_module(self):
|
||||
# self.assertIsInstance(AccelerateConnection(), AccelerateConnection)
|
||||
#
|
||||
# def test_chroot_connection_module(self):
|
||||
# self.assertIsInstance(ChrootConnection(), ChrootConnection)
|
||||
#
|
||||
# def test_funcd_connection_module(self):
|
||||
# self.assertIsInstance(FuncdConnection(), FuncdConnection)
|
||||
#
|
||||
# def test_jail_connection_module(self):
|
||||
# self.assertIsInstance(JailConnection(), JailConnection)
|
||||
#
|
||||
# def test_libvirt_lxc_connection_module(self):
|
||||
# self.assertIsInstance(LibvirtLXCConnection(), LibvirtLXCConnection)
|
||||
|
||||
def test_local_connection_module(self):
|
||||
self.assertIsInstance(LocalConnection(self.conn_info, self.in_stream), LocalConnection)
|
||||
|
||||
def test_paramiko_connection_module(self):
|
||||
self.assertIsInstance(ParamikoConnection(self.conn_info, self.in_stream), ParamikoConnection)
|
||||
|
||||
def test_ssh_connection_module(self):
|
||||
self.assertIsInstance(SSHConnection(self.conn_info, self.in_stream), SSHConnection)
|
||||
|
||||
# def test_winrm_connection_module(self):
|
||||
# self.assertIsInstance(WinRmConnection(), WinRmConnection)
|
77
test/units/plugins/test_plugins.py
Normal file
77
test/units/plugins/test_plugins.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
# (c) 2012-2014, 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 os
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests import BUILTINS
|
||||
|
||||
from ansible.compat.tests.mock import mock_open, patch, MagicMock
|
||||
|
||||
from ansible.plugins import MODULE_CACHE, PATH_CACHE, PLUGIN_PATH_CACHE, _basedirs, push_basedir, PluginLoader
|
||||
|
||||
class TestErrors(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
@patch.object(PluginLoader, '_get_paths')
|
||||
def test_print_paths(self, mock_method):
|
||||
mock_method.return_value = ['/path/one', '/path/two', '/path/three']
|
||||
pl = PluginLoader('foo', 'foo', '', 'test_plugins')
|
||||
paths = pl.print_paths()
|
||||
expected_paths = os.pathsep.join(['/path/one', '/path/two', '/path/three'])
|
||||
self.assertEqual(paths, expected_paths)
|
||||
|
||||
def test_plugins__get_package_paths_no_package(self):
|
||||
pl = PluginLoader('test', '', 'test', 'test_plugin')
|
||||
self.assertEqual(pl._get_package_paths(), [])
|
||||
|
||||
def test_plugins__get_package_paths_with_package(self):
|
||||
# the _get_package_paths() call uses __import__ to load a
|
||||
# python library, and then uses the __file__ attribute of
|
||||
# the result for that to get the library path, so we mock
|
||||
# that here and patch the builtin to use our mocked result
|
||||
m = MagicMock()
|
||||
m.return_value.__file__ = '/path/to/my/test.py'
|
||||
pl = PluginLoader('test', 'foo.bar.bam', 'test', 'test_plugin')
|
||||
with patch('{0}.__import__'.format(BUILTINS), m):
|
||||
self.assertEqual(pl._get_package_paths(), ['/path/to/my/bar/bam'])
|
||||
|
||||
def test_plugins__get_paths(self):
|
||||
pl = PluginLoader('test', '', 'test', 'test_plugin')
|
||||
pl._paths = ['/path/one', '/path/two']
|
||||
self.assertEqual(pl._get_paths(), ['/path/one', '/path/two'])
|
||||
|
||||
# NOT YET WORKING
|
||||
#def fake_glob(path):
|
||||
# if path == 'test/*':
|
||||
# return ['test/foo', 'test/bar', 'test/bam']
|
||||
# elif path == 'test/*/*'
|
||||
#m._paths = None
|
||||
#mock_glob = MagicMock()
|
||||
#mock_glob.return_value = []
|
||||
#with patch('glob.glob', mock_glob):
|
||||
# pass
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue