summaryrefslogtreecommitdiff
path: root/tests/unit/modules/base.py
diff options
context:
space:
mode:
authoromnom62 <omnom62@outlook.com>2026-05-27 21:38:51 +1000
committeromnom62 <omnom62@outlook.com>2026-05-27 21:38:51 +1000
commitaeedc73003ddcf84bbf5c2880f982b6d4925e0c9 (patch)
treeb2bf9705e2fe6db7dbaa51afc5fd60ca0f7878da /tests/unit/modules/base.py
parent5a6f6976b49fd5ca8e964b2342493bc5ceee85d5 (diff)
downloadrest.vyos-aeedc73003ddcf84bbf5c2880f982b6d4925e0c9.tar.gz
rest.vyos-aeedc73003ddcf84bbf5c2880f982b6d4925e0c9.zip
Test framework
Diffstat (limited to 'tests/unit/modules/base.py')
-rw-r--r--tests/unit/modules/base.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unit/modules/base.py b/tests/unit/modules/base.py
new file mode 100644
index 0000000..e5a602e
--- /dev/null
+++ b/tests/unit/modules/base.py
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+# GNU General Public License v3.0+
+
+from __future__ import absolute_import, division, print_function
+
+
+__metaclass__ = type
+
+import json
+import os
+import unittest
+
+from unittest.mock import MagicMock, patch # noqa: F401
+
+
+def load_fixture(filename):
+ """Load a JSON fixture file from tests/unit/fixtures/."""
+ fixtures_dir = os.path.join(os.path.dirname(__file__), "..", "fixtures")
+ path = os.path.join(fixtures_dir, filename)
+ with open(path) as f:
+ return json.load(f)
+
+
+class VyOSModuleTestCase(unittest.TestCase):
+ """
+ Base class for vyos.rest module unit tests.
+
+ Provides a mock VyOSModule that returns fixture data from
+ get_config() without any device connection.
+
+ Usage:
+ class TestVyOSNtpGlobal(VyOSModuleTestCase):
+ def setUp(self):
+ super().setUp()
+ self.fixture = load_fixture("ntp_global_running.json")
+
+ def test_merged_adds_new_server(self):
+ have = self.module.get_running_config_from_fixture(self.fixture)
+ commands = build_commands(want, have, "merged")
+ self.assertIn(("set", ["service", "ntp", "server", "1.2.3.4"]), commands)
+ """
+
+ def setUp(self):
+ self.mock_module = MagicMock()
+ self.mock_module.params = {}
+ self.mock_module.check_mode = False
+
+ self.mock_vyos = MagicMock()
+ self.mock_vyos.get_config = MagicMock(return_value={})
+
+ def set_running_config(self, data):
+ """Configure mock get_config to return given data."""
+ self.mock_vyos.get_config.return_value = data