summaryrefslogtreecommitdiffstats
path: root/ansible_collections/cisco/dnac/tests/unit
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-18 05:52:22 +0000
commit38b7c80217c4e72b1d8988eb1e60bb6e77334114 (patch)
tree356e9fd3762877d07cde52d21e77070aeff7e789 /ansible_collections/cisco/dnac/tests/unit
parentAdding upstream version 7.7.0+dfsg. (diff)
downloadansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.tar.xz
ansible-38b7c80217c4e72b1d8988eb1e60bb6e77334114.zip
Adding upstream version 9.4.0+dfsg.upstream/9.4.0+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/cisco/dnac/tests/unit')
-rw-r--r--ansible_collections/cisco/dnac/tests/unit/modules/dnac/dnac_module.py137
-rw-r--r--ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_discovery_intent.py170
-rw-r--r--ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_pnp_intent.py113
-rw-r--r--ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_site_intent.py100
-rw-r--r--ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_swim_intent.py134
-rw-r--r--ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_template_intent.py99
6 files changed, 660 insertions, 93 deletions
diff --git a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/dnac_module.py b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/dnac_module.py
index c05b5a6ee..2a2ee78ce 100644
--- a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/dnac_module.py
+++ b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/dnac_module.py
@@ -28,6 +28,7 @@ from ansible_collections.ansible.netcommon.tests.unit.modules.utils import (
from ansible_collections.ansible.netcommon.tests.unit.modules.utils import (
set_module_args as _set_module_args,
)
+from unittest.mock import patch
def set_module_args(args):
@@ -75,9 +76,107 @@ def load_fixture(module_name, name, device=""):
class TestDnacModule(ModuleTestCase):
+
+ def __init__(self, module):
+
+ """
+ Initialize an instance of class .
+
+ Parameters:
+ - module (ModuleType): The Python module associated with this instance.
+
+ Attributes:
+ - module (ModuleType): The provided module.
+ - test_data (dict): The loaded playbook data from the module.
+ - playbook_config (dict): The playbook configuration.
+ - playbook_config_missing_param (dict): The playbook configuration with missing parameters.
+ """
+
+ self.module = module
+ self.test_data = self.loadPlaybookData(str(self.module.__name__))
+ self.playbook_config = self.test_data.get("playbook_config")
+ self.playbook_config_missing_param = self.test_data.get("playbook_config_missing_param")
+
+ def setUp(self):
+
+ """
+ Set up the test environment by mocking Cisco DNA Center SDK initialization and execution.
+ This method is automatically called before each test case to ensure a clean and controlled environment.
+ Mocks the initialization and execution of the Cisco DNA Center SDK to isolate testing from actual SDK operations.
+
+ Mocked attributes:
+ - mock_dnac_init: Mocks the initialization of the DNACSDK class.
+ - run_dnac_init: The started mock for DNACSDK initialization.
+ - mock_dnac_exec: Mocks the execution of DNACSDK methods.
+ - run_dnac_exec: The started mock for DNACSDK method execution.
+ """
+
+ self.mock_dnac_init = patch(
+ "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.__init__")
+ self.run_dnac_init = self.mock_dnac_init.start()
+ self.run_dnac_init.side_effect = [None]
+ self.mock_dnac_exec = patch(
+ "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.exec"
+ )
+ self.run_dnac_exec = self.mock_dnac_exec.start()
+
+ def tearDown(self):
+
+ """
+ Clean up the test environment by stopping the mocked Cisco DNA Center SDK initialization and execution.
+ This method is automatically called after each test case to clean up any resources or mocks created during testing.
+ Stops the mock instances of the Cisco DNA Center SDK initialization and execution.
+ """
+
+ self.mock_dnac_exec.stop()
+ self.mock_dnac_init.stop()
+
+ def loadPlaybookData(self, module):
+
+ """
+ Load JSON data from a file.
+
+ Parameters:
+ - module (str): The name of the module used to construct the filename.
+
+ Returns:
+ - dict: The loaded JSON data.
+
+ Raises:
+ - FileNotFoundError: If the file does not exist.
+ - json.JSONDecodeError: If there is an error decoding the JSON data.
+ """
+
+ file_path = os.path.join(fixture_path, "{0}.json".format(module))
+ print(file_path)
+ try:
+ with open(file_path) as f:
+ data = f.read()
+ j_data = json.loads(data)
+ except Exception as e:
+ print(e)
+ pass
+
+ return j_data
+
def execute_module_devices(
self, failed=False, changed=False, response=None, sort=True, defaults=False
):
+
+ """
+ This method executes a module for a single device.
+
+ Parameters:
+ - failed (bool, optional): If True, check for failures. Defaults to False.
+ - changed (bool, optional): If True, check for changes. Defaults to False.
+ - response (list, optional): The expected response data. Defaults to None.
+ - sort (bool, optional): If True, sort the response data before comparison. Defaults to True.
+ - device (str, optional): The device to execute the module on. Defaults to an empty string.
+
+ Returns:
+ - dict: A dictionary containing the execution result.
+ """
+
module_name = self.module.__name__.rsplit(".", 1)[1]
local_fixture_path = os.path.join(fixture_path, module_name)
@@ -101,6 +200,22 @@ class TestDnacModule(ModuleTestCase):
self, failed=False, changed=False, response=None, sort=True, device=""
):
+ """
+ Execute a module for a specific device and perform validation.
+
+ This method executes the module for a specific device, performs validation checks, and returns the result.
+
+ Parameters:
+ - failed (bool, optional): If True, check for failures. Defaults to False.
+ - changed (bool, optional): If True, check for changes. Defaults to False.
+ - response (list, optional): The expected response data. Defaults to None.
+ - sort (bool, optional): If True, sort the response data before comparison. Defaults to True.
+ - device (str, optional): The device to execute the module on. Defaults to an empty string.
+
+ Returns:
+ - dict: A dictionary containing the execution result, including 'failed', 'changed', and 'response' keys.
+ """
+
self.load_fixtures(response, device=device)
if failed:
@@ -121,6 +236,14 @@ class TestDnacModule(ModuleTestCase):
return result
def failed(self):
+
+ """
+ Check for failures during module execution.
+
+ Returns:
+ - dict: A dictionary containing the failure status and additional information.
+ """
+
with self.assertRaises(AnsibleFailJson) as exc:
self.module.main()
@@ -129,12 +252,20 @@ class TestDnacModule(ModuleTestCase):
return result
def changed(self, changed=False):
+
+ """
+ Check for changes during module execution.
+
+ Parameters:
+ - changed (bool, optional): If True, check for changes. Defaults to False.
+
+ Returns:
+ - dict: A dictionary containing the change status and additional information.
+ """
+
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, response=None, device=""):
- pass
diff --git a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_discovery_intent.py b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_discovery_intent.py
new file mode 100644
index 000000000..82f9999de
--- /dev/null
+++ b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_discovery_intent.py
@@ -0,0 +1,170 @@
+# Copyright (c) 2020 Cisco and/or its affiliates.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Make coding more python3-ish
+from __future__ import absolute_import, division, print_function
+
+__metaclass__ = type
+
+from ansible_collections.cisco.dnac.plugins.modules import discovery_intent
+from .dnac_module import TestDnacModule, set_module_args
+
+
+class TestDnacDiscoveryIntent(TestDnacModule):
+ def __init__(self):
+
+ """
+ Inheriting from the base class of dnac_module
+ """
+
+ module = discovery_intent
+ super().__init__(module)
+
+ def load_fixtures(self, response=None, device=""):
+
+ """
+ Load fixtures for a specific device.
+
+ Parameters:
+ response (list, optional): The expected response data. Defaults to None.
+ device (str, optional): The device for which to load fixtures. Defaults to an empty string.
+ """
+
+ if "create_discovery" in self._testMethodName:
+ self.run_dnac_exec.side_effect = [
+ Exception(),
+ self.test_data.get("create_discovery_response"),
+ self.test_data.get("get_business_api_execution_details_response"),
+ self.test_data.get("get_discovery_response")
+ ]
+ elif "delete_existing_discovery" in self._testMethodName:
+ self.run_dnac_exec.side_effect = [
+ self.test_data.get("delete_get_discovery_response"),
+ self.test_data.get("delete_delete_discovery_response"),
+ self.test_data.get("get_business_api_execution_details_response")
+ ]
+ elif "delete_non_existing_discovery" in self._testMethodName:
+ self.run_dnac_exec.side_effect = [
+ Exception()
+ ]
+ elif "error_delete" in self._testMethodName:
+ self.run_dnac_exec.side_effect = [
+ self.test_data.get("delete_error_get_discovery_response"),
+ self.test_data.get("delete_delete_discovery_response"),
+ self.test_data.get("delete_execution_details_error")
+ ]
+ elif "error_create" in self._testMethodName:
+ self.run_dnac_exec.side_effect = [
+ Exception(),
+ self.test_data.get("create_discovery_response"),
+ self.test_data.get("delete_execution_details_error")
+ ]
+
+ def test_discovery_intent_create_discovery(self):
+ set_module_args(
+ dict(
+ dnac_host="172.23.241.186",
+ dnac_username="admin",
+ dnac_password="Maglev123",
+ dnac_verify=False,
+ dnac_log=True,
+ state="merged",
+ headers=None,
+ name=self.playbook_config.get('name'),
+ devices_list=self.playbook_config.get('devices_list'),
+ discoveryType="MULTI RANGE",
+ protocolOrder="ssh",
+ startIndex=1,
+ recordsToReturn=25
+ )
+ )
+ result = self.execute_module(changed=True, failed=False)
+ self.assertEqual(
+ result.get('msg'),
+ "Discovery Created Successfully"
+ )
+
+ def test_discovery_intent_delete_existing_discovery(self):
+ set_module_args(
+ dict(
+ dnac_host="172.23.241.186",
+ dnac_username="admin",
+ dnac_password="Maglev123",
+ dnac_verify=False,
+ dnac_log=True,
+ state="deleted",
+ headers=None,
+ name=self.playbook_config.get('name'),
+ devices_list=self.playbook_config.get('devices_list'),
+ discoveryType="MULTI RANGE",
+ protocolOrder="ssh",
+ startIndex=1,
+ recordsToReturn=25
+ )
+ )
+ result = self.execute_module(changed=True, failed=False)
+ self.assertEqual(
+ result.get('msg'),
+ "Discovery Deleted Successfully"
+ )
+
+ def test_discovery_intent_delete_non_existing_discovery(self):
+ set_module_args(
+ dict(
+ dnac_host="172.23.241.186",
+ dnac_username="admin",
+ dnac_password="Maglev123",
+ dnac_verify=False,
+ dnac_log=True,
+ state="deleted",
+ headers=None,
+ name=self.playbook_config.get('delete_non_exist_discovery_name'),
+ devices_list=self.playbook_config.get('devices_list'),
+ discoveryType="MULTI RANGE",
+ protocolOrder="ssh",
+ startIndex=1,
+ recordsToReturn=25
+ )
+ )
+ result = self.execute_module(changed=False, failed=False)
+ self.assertIsNone(result.get('exist_discovery'))
+ self.assertEqual(
+ result.get('msg'),
+ f"Discovery {self.playbook_config.get('delete_non_exist_discovery_name')} Not Found"
+ )
+
+ def test_discovery_intent_invalid_state(self):
+
+ set_module_args(
+ dict(
+ dnac_host="172.23.241.186",
+ dnac_username="admin",
+ dnac_password="Maglev123",
+ dnac_verify=False,
+ dnac_log=True,
+ state="present",
+ headers=None,
+ name=self.playbook_config.get('name'),
+ devices_list=self.playbook_config.get('devices_list'),
+ discoveryType="MULTI RANGE",
+ protocolOrder="ssh",
+ startIndex=1,
+ recordsToReturn=25
+ )
+ )
+ result = self.execute_module(changed=False, failed=True)
+ self.assertEqual(
+ result.get('msg'),
+ "value of state must be one of: merged, deleted, got: present"
+ )
diff --git a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_pnp_intent.py b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_pnp_intent.py
index b3c15a4ff..6f93e2a8a 100644
--- a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_pnp_intent.py
+++ b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_pnp_intent.py
@@ -17,39 +17,31 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from unittest.mock import patch
from ansible.errors import AnsibleActionFail
from ansible_collections.cisco.dnac.plugins.modules import pnp_intent
-from .dnac_module import TestDnacModule, set_module_args, loadPlaybookData
+from .dnac_module import TestDnacModule, set_module_args
class TestDnacPnPIntent(TestDnacModule):
+ def __init__(self):
- module = pnp_intent
+ """
+ Inheriting from the base class of dnac_module
+ """
- test_data = loadPlaybookData("pnp_intent")
+ module = pnp_intent
+ super().__init__(module)
- playbook_config = test_data.get("playbook_config")
- playbook_config_missing_param = test_data.get("playbook_config_missing_param")
-
- def setUp(self):
- super(TestDnacPnPIntent, self).setUp()
+ def load_fixtures(self, response=None, device=""):
- self.mock_dnac_init = patch(
- "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.__init__")
- self.run_dnac_init = self.mock_dnac_init.start()
- self.run_dnac_init.side_effect = [None]
- self.mock_dnac_exec = patch(
- "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.exec"
- )
- self.run_dnac_exec = self.mock_dnac_exec.start()
+ """
+ Load fixtures for a specific device.
- def tearDown(self):
- super(TestDnacPnPIntent, self).tearDown()
- self.mock_dnac_exec.stop()
- self.mock_dnac_init.stop()
+ Parameters:
+ response (list, optional): The expected response data. Defaults to None.
+ device (str, optional): The device for which to load fixtures. Defaults to an empty string.
+ """
- def load_fixtures(self, response=None, device=""):
if "site_not_found" in self._testMethodName:
self.run_dnac_exec.side_effect = [
self.test_data.get("image_exists_response"),
@@ -111,6 +103,13 @@ class TestDnacPnPIntent(TestDnacModule):
]
def test_pnp_intent_site_not_found(self):
+
+ """
+ Test case for PnP intent when site is not found.
+
+ This test case checks the behavior of the PnP intent when the site is not found in the specified DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -128,6 +127,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_add_new_device(self):
+
+ """
+ Test case for PnP intent when adding a new device.
+
+ This test case checks the behavior of the PnP intent when adding a new device in the specified DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -145,6 +151,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_device_exists(self):
+
+ """
+ Test case for PnP intent when a device already exists.
+
+ This test case checks the behavior of the PnP intent when a device already exists in the specified DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -162,6 +175,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_image_doesnot_exist(self):
+
+ """
+ Test case for PnP intent when an image does not exist.
+
+ This test case checks the behavior of the PnP intent when the specified image is not found in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -179,6 +199,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_template_doesnot_exist(self):
+
+ """
+ Test case for PnP intent when a template does not exist.
+
+ This test case checks the behavior of the PnP intent when the specified template is not found in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -196,6 +223,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_project_not_found(self):
+
+ """
+ Test case for PnP intent when a project is not found.
+
+ This test case checks the behavior of the PnP intent when the specified project is not found in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -213,6 +247,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_missing_param(self):
+
+ """
+ Test case for PnP intent with missing parameters in the playbook.
+
+ This test case checks the behavior of the PnP intent when the playbook contains missing required parameters.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -230,6 +271,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_delete_device(self):
+
+ """
+ Test case for PnP intent when deleting a device.
+
+ This test case checks the behavior of the PnP intent when deleting a device in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -247,6 +295,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_deletion_error(self):
+
+ """
+ Test case for PnP intent when device deletion fails.
+
+ This test case checks the behavior of the PnP intent when device deletion fails in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -264,6 +319,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_delete_nonexisting_device(self):
+
+ """
+ Test case for PnP intent when deleting a non-existing device.
+
+ This test case checks the behavior of the PnP intent when trying to delete a device that doesn't exist in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -281,6 +343,13 @@ class TestDnacPnPIntent(TestDnacModule):
)
def test_pnp_intent_invalid_state(self):
+
+ """
+ Test case for PnP intent with an invalid state parameter.
+
+ This test case checks the behavior of the PnP intent when an invalid 'state' parameter is provided in the playbook.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
diff --git a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_site_intent.py b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_site_intent.py
index a12f1d1c4..089d4ee85 100644
--- a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_site_intent.py
+++ b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_site_intent.py
@@ -17,39 +17,29 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from unittest.mock import patch
-
from ansible_collections.cisco.dnac.plugins.modules import site_intent
-from .dnac_module import TestDnacModule, set_module_args, loadPlaybookData
+from .dnac_module import TestDnacModule, set_module_args
class TestDnacSiteIntent(TestDnacModule):
+ def __init__(self):
+ """
+ Inheriting from the base class of dnac_module
+ """
- module = site_intent
-
- test_data = loadPlaybookData("site_intent")
+ module = site_intent
+ super().__init__(module)
- playbook_config = test_data.get("playbook_config")
- playbook_config_missing_param = test_data.get("playbook_config_missing_param")
-
- def setUp(self):
- super(TestDnacSiteIntent, self).setUp()
+ def load_fixtures(self, response=None, device=""):
- self.mock_dnac_init = patch(
- "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.__init__")
- self.run_dnac_init = self.mock_dnac_init.start()
- self.run_dnac_init.side_effect = [None]
- self.mock_dnac_exec = patch(
- "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.exec"
- )
- self.run_dnac_exec = self.mock_dnac_exec.start()
+ """
+ Load fixtures for a specific device.
- def tearDown(self):
- super(TestDnacSiteIntent, self).tearDown()
- self.mock_dnac_exec.stop()
- self.mock_dnac_init.stop()
+ Parameters:
+ response (list, optional): The expected response data. Defaults to None.
+ device (str, optional): The device for which to load fixtures. Defaults to an empty string.
+ """
- def load_fixtures(self, response=None, device=""):
if "create_site" in self._testMethodName:
self.run_dnac_exec.side_effect = [
Exception(),
@@ -93,6 +83,13 @@ class TestDnacSiteIntent(TestDnacModule):
]
def test_site_intent_create_site(self):
+
+ """
+ Test case for site intent when creating a site.
+
+ This test case checks the behavior of the site intent when creating a new site in the specified DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -110,6 +107,13 @@ class TestDnacSiteIntent(TestDnacModule):
)
def test_site_intent_update_not_needed(self):
+
+ """
+ Test case for site intent when no update is needed.
+
+ This test case checks the behavior of the site intent when an update is not required for the specified site in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -127,6 +131,13 @@ class TestDnacSiteIntent(TestDnacModule):
)
def test_site_intent_update_needed(self):
+
+ """
+ Test case for site intent when an update is needed.
+
+ This test case checks the behavior of the site intent when an update is required for the specified site in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -144,6 +155,13 @@ class TestDnacSiteIntent(TestDnacModule):
)
def test_site_intent_delete_existing_site(self):
+
+ """
+ Test case for site intent when deleting an existing site.
+
+ This test case checks the behavior of the site intent when deleting an existing site in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -161,6 +179,13 @@ class TestDnacSiteIntent(TestDnacModule):
)
def test_site_intent_delete_non_existing_site(self):
+
+ """
+ Test case for site intent when attempting to delete a non-existing site.
+
+ This test case checks the behavior of the site intent when trying to delete a site that does not exist in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -178,6 +203,13 @@ class TestDnacSiteIntent(TestDnacModule):
)
def test_site_intent_invalid_param(self):
+
+ """
+ Test case for site intent with invalid parameters in the playbook.
+
+ This test case checks the behavior of the site intent when the playbook contains invalid parameters.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -194,6 +226,13 @@ class TestDnacSiteIntent(TestDnacModule):
)
def test_site_intent_error_delete(self):
+
+ """
+ Test case for site intent when an error occurs during site deletion.
+
+ This test case checks the behavior of the site intent when an error occurs while deleting a site in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -211,6 +250,13 @@ class TestDnacSiteIntent(TestDnacModule):
)
def test_site_intent_error_create(self):
+
+ """
+ Test case for site intent when an error occurs during site creation.
+
+ This test case checks the behavior of the site intent when an error occurs while creating a site in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -229,6 +275,12 @@ class TestDnacSiteIntent(TestDnacModule):
def test_site_intent_invalid_state(self):
+ """
+ Test case for site intent with an invalid 'state' parameter.
+
+ This test case checks the behavior of the site intent when an invalid 'state' parameter is provided in the playbook.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
diff --git a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_swim_intent.py b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_swim_intent.py
index 18acf4762..d2915e621 100644
--- a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_swim_intent.py
+++ b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_swim_intent.py
@@ -17,37 +17,29 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from unittest.mock import patch
-
from ansible_collections.cisco.dnac.plugins.modules import swim_intent
-from .dnac_module import TestDnacModule, set_module_args, loadPlaybookData
+from .dnac_module import TestDnacModule, set_module_args
class TestDnacSwimIntent(TestDnacModule):
+ def __init__(self):
+ """
+ Inheriting from the base class of dnac_module
+ """
- module = swim_intent
- test_data = loadPlaybookData("swim_intent")
- playbook_config = test_data.get("playbook_config")
- playbook_config_untag_image = test_data.get("playbook_config_untag_golden_image")
+ module = swim_intent
+ super().__init__(module)
- def setUp(self):
- super(TestDnacSwimIntent, self).setUp()
+ def load_fixtures(self, response=None, device=""):
- self.mock_dnac_init = patch(
- "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.__init__")
- self.run_dnac_init = self.mock_dnac_init.start()
- self.run_dnac_init.side_effect = [None]
- self.mock_dnac_exec = patch(
- "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.exec"
- )
- self.run_dnac_exec = self.mock_dnac_exec.start()
+ """
+ Load fixtures for a specific device.
- def tearDown(self):
- super(TestDnacSwimIntent, self).tearDown()
- self.mock_dnac_exec.stop()
- self.mock_dnac_init.stop()
+ Parameters:
+ response (list, optional): The expected response data. Defaults to None.
+ device (str, optional): The device for which to load fixtures. Defaults to an empty string.
+ """
- def load_fixtures(self, response=None, device=""):
if "full_flow" in self._testMethodName:
self.run_dnac_exec.side_effect = [
self.test_data.get("task_info_response"),
@@ -117,6 +109,13 @@ class TestDnacSwimIntent(TestDnacModule):
]
def test_swim_full_flow(self):
+
+ """
+ Test case for a full Software Image Management (SWIM) flow.
+
+ This test case covers the full SWIM flow, including image activation, import, tagging, distribution, and various error scenarios.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -133,6 +132,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_image_import(self):
+
+ """
+ Test case for SWIM image import when the image already exists.
+
+ This test case checks the behavior of SWIM when importing an image that already exists in the specified DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -149,6 +155,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_image_local_import(self):
+
+ """
+ Test case for SWIM local image import when the image already exists.
+
+ This test case checks the behavior of SWIM when importing a local image that already exists in the specified DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -165,6 +178,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_untag_image(self):
+
+ """
+ Test case for SWIM untagging an image as Golden.
+
+ This test case checks the behavior of SWIM when untagging an image as a Golden image in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -181,6 +201,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_missing_param_tag_golden_image(self):
+
+ """
+ Test case for SWIM with missing parameters for tagging a Golden image.
+
+ This test case checks the behavior of SWIM when attempting to tag an image as Golden with missing parameters.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -197,6 +224,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_incorrect_site_untag_golden_image(self):
+
+ """
+ Test case for SWIM when trying to untag an image from a non-existing site.
+
+ This test case checks the behavior of SWIM when attempting to untag an image from a non-existing site.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -213,6 +247,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_image_doesnot_exist_response(self):
+
+ """
+ Test case for SWIM when the image does not exist in the response.
+
+ This test case checks the behavior of SWIM when the requested image is not found in the DNAC response.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -229,6 +270,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_only_image_distribution(self):
+
+ """
+ Test case for SWIM with only image distribution.
+
+ This test case checks the behavior of SWIM when distributing an image to devices.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -245,6 +293,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_image_distribution_missing_param(self):
+
+ """
+ Test case for SWIM image distribution with missing parameters.
+
+ This test case checks the behavior of SWIM when attempting to distribute an image with missing parameters.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -261,6 +316,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_only_image_activation(self):
+
+ """
+ Test case for SWIM with only image activation.
+
+ This test case checks the behavior of SWIM when activating an image.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -277,6 +339,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_image_activation_missing_param(self):
+
+ """
+ Test case for SWIM image activation with missing parameters.
+
+ This test case checks the behavior of SWIM when attempting to activate an image with missing parameters.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -293,6 +362,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_tag_golden_incorrect_family_name(self):
+
+ """
+ Test case for SWIM when tagging an image as Golden with an incorrect family name.
+
+ This test case checks the behavior of SWIM when attempting to tag an image as Golden with an incorrect family device name.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -309,6 +385,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_device_doesnot_exist(self):
+
+ """
+ Test case for SWIM when the device does not exist.
+
+ This test case checks the behavior of SWIM when the specified device is not found in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -325,6 +408,13 @@ class TestDnacSwimIntent(TestDnacModule):
)
def test_swim_incorrect_image_import_parameter(self):
+
+ """
+ Test case for SWIM with incorrect image import parameters.
+
+ This test case checks the behavior of SWIM when using incorrect image import parameters.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
diff --git a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_template_intent.py b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_template_intent.py
index c0f866d46..512d31a82 100644
--- a/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_template_intent.py
+++ b/ansible_collections/cisco/dnac/tests/unit/modules/dnac/test_template_intent.py
@@ -17,37 +17,29 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type
-from unittest.mock import patch
from ansible_collections.cisco.dnac.plugins.modules import template_intent
-from .dnac_module import TestDnacModule, set_module_args, loadPlaybookData
+from .dnac_module import TestDnacModule, set_module_args
class TestDnacTemplateIntent(TestDnacModule):
+ def __init__(self):
+ """
+ Inheriting from the base class of dnac_module
+ """
- module = template_intent
+ module = template_intent
+ super().__init__(module)
- test_data = loadPlaybookData("template_intent")
-
- playbook_config = test_data.get("playbook_config")
- playbook_config_missing_param = test_data.get("playbook_config_missing_param")
+ def load_fixtures(self, response=None, device=""):
- def setUp(self):
- super(TestDnacTemplateIntent, self).setUp()
- self.mock_dnac_init = patch(
- "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.__init__")
- self.run_dnac_init = self.mock_dnac_init.start()
- self.run_dnac_init.side_effect = [None]
- self.mock_dnac_exec = patch(
- "ansible_collections.cisco.dnac.plugins.module_utils.dnac.DNACSDK.exec"
- )
- self.run_dnac_exec = self.mock_dnac_exec.start()
+ """
+ Load fixtures for a specific device.
- def tearDown(self):
- super(TestDnacTemplateIntent, self).tearDown()
- self.mock_dnac_exec.stop()
- self.mock_dnac_init.stop()
+ Parameters:
+ response (list, optional): The expected response data. Defaults to None.
+ device (str, optional): The device for which to load fixtures. Defaults to an empty string.
+ """
- def load_fixtures(self, response=None, device=""):
if "create_template" in self._testMethodName:
self.run_dnac_exec.side_effect = [
self.test_data.get("create_template_list_response"),
@@ -87,6 +79,13 @@ class TestDnacTemplateIntent(TestDnacModule):
]
def test_template_intent_create_template(self):
+
+ """
+ Test case for template intent when creating a template.
+
+ This test case checks the behavior of the template intent when creating a new template in the specified DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -104,6 +103,13 @@ class TestDnacTemplateIntent(TestDnacModule):
)
def test_template_intent_update_not_needed(self):
+
+ """
+ Test case for template intent when no update is needed.
+
+ This test case checks the behavior of the template intent when an update is not required for the specified template in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -121,6 +127,13 @@ class TestDnacTemplateIntent(TestDnacModule):
)
def test_template_intent_update_needed(self):
+
+ """
+ Test case for template intent when an update is needed.
+
+ This test case checks the behavior of the template intent when an update is required for the specified template in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -138,6 +151,13 @@ class TestDnacTemplateIntent(TestDnacModule):
)
def test_template_intent_project_not_found(self):
+
+ """
+ Test case for template intent when the project is not found.
+
+ This test case checks the behavior of the template intent when the specified project is not found in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -155,6 +175,13 @@ class TestDnacTemplateIntent(TestDnacModule):
)
def test_template_intent_delete_non_existing_template(self):
+
+ """
+ Test case for template intent when trying to delete a non-existing template.
+
+ This test case checks the behavior of the template intent when trying to delete a template that does not exist in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -172,6 +199,13 @@ class TestDnacTemplateIntent(TestDnacModule):
)
def test_template_intent_delete_template(self):
+
+ """
+ Test case for template intent when deleting a template.
+
+ This test case checks the behavior of the template intent when deleting an existing template in the DNAC.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -189,6 +223,13 @@ class TestDnacTemplateIntent(TestDnacModule):
)
def test_template_intent_missing_param(self):
+
+ """
+ Test case for template intent with missing parameters in the playbook.
+
+ This test case checks the behavior of the template intent when the playbook contains missing required parameters.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -206,6 +247,13 @@ class TestDnacTemplateIntent(TestDnacModule):
)
def test_template_intent_invalid_state(self):
+
+ """
+ Test case for template intent with an invalid 'state' parameter.
+
+ This test case checks the behavior of the template intent when an invalid 'state' parameter is provided in the playbook.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",
@@ -223,6 +271,13 @@ class TestDnacTemplateIntent(TestDnacModule):
)
def test_template_intent_invalid_param(self):
+
+ """
+ Test case for template intent with invalid parameters in the playbook.
+
+ This test case checks the behavior of the template intent when the playbook contains invalid parameters.
+ """
+
set_module_args(
dict(
dnac_host="1.1.1.1",