48e83c39ba
* add asa_og module * add test * fix pep8 * fix some sanity pylint * fix import error order * fix import * replace cmd() method * rename file and class * add mock for connection * fix commands in replace test function * fix lines list * update unit test * fix 'and' logic for port-object command * restore previous unit test; fix pep8 and remove debug * other unit tests * Add state present, absent, replace * Update doc; add default for state * update unit test with state present/absent * fix typo in unit test * fix pep8 too many blank lines * fix show run for service object ASA Ver 8.x * Add description field; fix bug for state present and absent * Re-designed module structure for network, service and port objects * update integration test for new module structure * fix pep8 * update EXAMPLES and RETURN * update units tests * fix module typos in unit test * removed provider from examples * fix missing comma in replace test * fix module name and remove provider * update license * remove register; update license; change import order; chage def state * remove shebang * fix doc default state * change import order * Update year in banner * fix integration test as set of tasks * remove arg_spec * remove extends_documentation_fragment: asa * Update DOC, remove unused import, change import order
76 lines
1.9 KiB
Python
76 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# (c) 2019, Ansible by Red Hat, inc
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# Make coding more python3-ish
|
|
from __future__ import (absolute_import, division, print_function)
|
|
__metaclass__ = type
|
|
|
|
import os
|
|
import json
|
|
|
|
from units.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 f:
|
|
data = f.read()
|
|
|
|
try:
|
|
data = json.loads(data)
|
|
except Exception:
|
|
pass
|
|
|
|
fixture_data[path] = data
|
|
return data
|
|
|
|
|
|
class TestAsaModule(ModuleTestCase):
|
|
|
|
def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False):
|
|
|
|
self.load_fixtures(commands)
|
|
|
|
if failed:
|
|
result = self.failed()
|
|
self.assertTrue(result['failed'], result)
|
|
else:
|
|
result = self.changed(changed)
|
|
self.assertEqual(result['changed'], changed, result)
|
|
|
|
if commands is not None:
|
|
if sort:
|
|
self.assertEqual(sorted(commands), sorted(result['commands']), result['commands'])
|
|
else:
|
|
self.assertEqual(commands, result['commands'], result['commands'])
|
|
|
|
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, commands=None):
|
|
pass
|