1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-04-05 03:37:01 +00:00

Move modules and module_utils unit tests to correct place (#81)

* Move modules and module_utils unit tests to correct place.

* Update ignore.txt

* Fix imports.

* Fix typos.

* Fix more typos.
This commit is contained in:
Felix Fontein 2020-03-31 10:42:38 +02:00 committed by GitHub
parent ab3c2120fb
commit be191cce6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1170 changed files with 732 additions and 751 deletions

View file

@ -0,0 +1,10 @@
[
{
"href": "http://192.168.1.1/api/v1/misc/dns_servers/1",
"data": {
"number": "1",
"server": "192.168.1.20"
},
"id": 1
}
]

View file

@ -0,0 +1,18 @@
[
{
"table": "misc.dns_servers",
"data": {
"number": "1",
"server": "192.168.1.20"
},
"id": 1
},
{
"table": "misc.dns_servers",
"data": {
"number": "2",
"server": "192.168.1.30"
},
"id": 2
}
]

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,7 @@
[
{
"load-factory": {
"msg": "reverted the configuration to the factory configuration."
}
}
]

View file

@ -0,0 +1,20 @@
[
{
"table": "misc.dns_servers",
"href": "http://10.48.28.78/api/v1/misc/dns_servers/1",
"data": {
"number": "1",
"server": "192.168.1.20"
},
"id": 1
},
{
"table": "misc.dns_servers",
"href": "http://10.48.28.78/api/v1/misc/dns_servers/2",
"data": {
"number": "2",
"server": "192.168.1.30"
},
"id": 2
}
]

View file

@ -0,0 +1,10 @@
[
{
"table": "misc.unitname",
"href": "http://10.48.28.78/api/v1/misc/unitname/1",
"data": {
"unitname": "\"Testapi - 1541699806\""
},
"id": 1
}
]

View file

@ -0,0 +1,7 @@
[
{
"revert-edits": {
"msg": "reverted the configuration to the last applied configuration."
}
}
]

View file

@ -0,0 +1,7 @@
[
{
"store-edit": {
"msg": "Successfully applied and saved the configuration."
}
}
]

View file

@ -0,0 +1,21 @@
[
{
"unit-information": {
"lic_email": "dev@ingate.com",
"lang": "en",
"product": "Software SIParator/Firewall",
"installid": "any",
"patches": [],
"lic_mac": "any",
"unitname": "testname",
"interfaces": "eth0 eth1 eth2 eth3 eth4 eth5",
"modules": "failover vpn sip qturn ems qos rsc voipsm idsips siptrunk sipswitch",
"lic_name": "Ingate",
"macaddr": "52:54:00:4c:e2:07",
"version": "6.2.0-erik",
"systemid": "IG-200-840-5001-0",
"mode": "Firewall",
"serial": "IG-200-840-5001-0"
}
}
]

View file

@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018, Ingate Systems AB
#
# 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/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import json
from ansible_collections.community.general.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
if path in fixture_data:
return fixture_data[path]
with open(path) as file_desc:
data = file_desc.read()
try:
data = json.loads(data)
except Exception:
pass
fixture_data[path] = data
return data
class TestIngateModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False, fixture=None,
command=None):
self.load_fixtures(fixture, command, changed)
if failed:
result = self.failed()
self.assertTrue(result['failed'], result)
else:
result = self.changed(changed)
self.assertEqual(result['changed'], changed, result)
return result
def failed(self):
with self.assertRaises(AnsibleFailJson) as exc:
self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
return result
def changed(self, changed=False):
with self.assertRaises(AnsibleExitJson) as exc:
self.module.main()
result = exc.exception.args[0]
self.assertEqual(result['changed'], changed, result)
return result
def load_fixtures(self, fixture=None, command=None, changed=False):
pass

View file

@ -0,0 +1,242 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018, Ingate Systems AB
#
# 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/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.ingate import ig_config
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .ingate_module import TestIngateModule, load_fixture
class TestConfigModule(TestIngateModule):
module = ig_config
def setUp(self):
super(TestConfigModule, self).setUp()
self.mock_make_request = patch('ansible_collections.community.general.'
'plugins.modules.network.ingate.'
'ig_config.make_request')
self.make_request = self.mock_make_request.start()
# ATM the Ingate Python SDK is not needed in this unit test.
self.module.HAS_INGATESDK = True
def tearDown(self):
super(TestConfigModule, self).tearDown()
self.mock_make_request.stop()
def load_fixtures(self, fixture=None, command=None, changed=False):
self.make_request.side_effect = [(changed, command,
load_fixture(fixture))]
def test_ig_config_add(self):
"""Test adding a row to a table.
"""
command = 'add'
set_module_args(dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
),
add=True,
table='misc.dns_servers',
columns=dict(
server='192.168.1.23'
)))
fixture = '%s_%s.%s' % (os.path.basename(__file__).split('.')[0],
command, 'json')
result = self.execute_module(changed=True, fixture=fixture,
command=command)
self.assertTrue(command in result)
def test_ig_config_delete(self):
"""Test deleting all rows in a table.
"""
command = 'delete'
set_module_args(dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
),
delete=True,
table='misc.dns_servers',
))
fixture = '%s_%s.%s' % (os.path.basename(__file__).split('.')[0],
command, 'json')
result = self.execute_module(changed=True, fixture=fixture,
command=command)
self.assertTrue(command in result)
def test_ig_config_get(self):
"""Test returning all rows in a table.
"""
command = 'get'
set_module_args(dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
),
get=True,
table='misc.dns_servers',
))
fixture = '%s_%s.%s' % (os.path.basename(__file__).split('.')[0],
command, 'json')
result = self.execute_module(changed=True, fixture=fixture,
command=command)
self.assertTrue(command in result)
def test_ig_config_modify(self):
"""Test modifying a row.
"""
command = 'modify'
set_module_args(dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
),
modify=True,
table='misc.unitname',
columns=dict(
unitname='"Testapi - 1541699806"'
)))
fixture = '%s_%s.%s' % (os.path.basename(__file__).split('.')[0],
command, 'json')
result = self.execute_module(changed=True, fixture=fixture,
command=command)
self.assertTrue(command in result)
def test_ig_config_revert(self):
"""Test reverting the preliminary configuration.
"""
command = 'revert'
set_module_args(dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
),
revert=True
))
fixture = '%s_%s.%s' % (os.path.basename(__file__).split('.')[0],
command, 'json')
result = self.execute_module(changed=True, fixture=fixture,
command=command)
self.assertTrue(command in result)
def test_ig_config_factory(self):
"""Test loading factory defaults.
"""
command = 'factory'
set_module_args(dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
),
factory=True
))
fixture = '%s_%s.%s' % (os.path.basename(__file__).split('.')[0],
command, 'json')
result = self.execute_module(changed=True, fixture=fixture,
command=command)
self.assertTrue(command in result)
def test_ig_config_store(self):
"""Test storing the preliminary configuration.
"""
command = 'store'
set_module_args(dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
),
store=True
))
fixture = '%s_%s.%s' % (os.path.basename(__file__).split('.')[0],
command, 'json')
result = self.execute_module(changed=True, fixture=fixture,
command=command)
self.assertTrue(command in result)
def test_ig_config_download(self):
"""Test doing backup of configuration database.
"""
command = 'store'
set_module_args(dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
),
download=True
))
fixture = '%s_%s.%s' % (os.path.basename(__file__).split('.')[0],
command, 'json')
result = self.execute_module(changed=True, fixture=fixture,
command=command)
self.assertTrue(command in result)
def test_ig_config_return_rowid(self):
"""Test retrieving a row id.
"""
command = 'return_rowid'
set_module_args(dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
),
return_rowid=True,
table='network.local_nets',
columns=dict(
interface='eth0'
)))
fixture = '%s_%s.%s' % (os.path.basename(__file__).split('.')[0],
command, 'json')
result = self.execute_module(changed=True, fixture=fixture,
command=command)
self.assertTrue(command in result)

View file

@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-
# Copyright: (c) 2018, Ingate Systems AB
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
from ansible_collections.community.general.tests.unit.compat.mock import patch
from ansible_collections.community.general.plugins.modules.network.ingate import ig_unit_information
from ansible_collections.community.general.tests.unit.plugins.modules.utils import set_module_args
from .ingate_module import TestIngateModule, load_fixture
class TestUnitInformationModule(TestIngateModule):
module = ig_unit_information
def setUp(self):
super(TestUnitInformationModule, self).setUp()
self.mock_make_request = patch('ansible_collections.community.general.'
'plugins.modules.network.ingate.'
'ig_unit_information.make_request')
self.make_request = self.mock_make_request.start()
self.mock_is_ingatesdk_installed = patch('ansible_collections.community.general.'
'plugins.modules.network.ingate.'
'ig_unit_information.is_ingatesdk_installed')
self.is_ingatesdk_installed = self.mock_is_ingatesdk_installed.start()
def tearDown(self):
super(TestUnitInformationModule, self).tearDown()
self.mock_make_request.stop()
self.mock_is_ingatesdk_installed.stop()
def load_fixtures(self, fixture=None, command=None, changed=False):
self.make_request.side_effect = [load_fixture(fixture)]
self.is_ingatesdk_installed.return_value = True
def test_ig_unit_information(self):
set_module_args(
dict(
client=dict(
version='v1',
address='127.0.0.1',
scheme='http',
username='alice',
password='foobar'
)
)
)
fixture = '%s.%s' % (os.path.basename(__file__).split('.')[0], 'json')
result = self.execute_module(fixture=fixture)
self.assertTrue('unit-information' in result)