From d329ddc4ad879579a436792d44b34ba4cecd270c Mon Sep 17 00:00:00 2001 From: IluaAir Date: Sat, 6 Jun 2026 13:55:51 +0300 Subject: [PATCH] Add unit tests for device registry model parsing - Introduced a new test file `test_models.py` to implement unit tests for various device models in the `device_registry`. - Added parameterized tests to validate the parsing of device configurations against expected JSON outputs and to ensure required sections are present in the parsed models. - Enhanced test coverage for multiple device types including Mikrotik, Keenetic, Qtech, Huawei, Eltex, and Quasar. --- tests/test_models.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/test_models.py diff --git a/tests/test_models.py b/tests/test_models.py new file mode 100644 index 0000000..f9f1f6f --- /dev/null +++ b/tests/test_models.py @@ -0,0 +1,38 @@ +import json + +import pytest + +from conftest import FIXTURES, load +from oxi.interfaces import device_registry + +MODEL_CASES = [ + ("mikrotik", "config.conf", "config.expected.json"), + ("keenetic", "config.conf", "config.expected.json"), + ("qtech", "config_1.conf", "config_1.expected.json"), + ("qtech", "config_2.conf", "config_2.expected.json"), + ("huawei", "config.conf", "config.expected.json"), + ("eltex", "config.conf", "config.expected.json"), + ("quasar", "config_1.conf", "config_1.expected.json"), + ("quasar", "config_2.conf", "config_2.expected.json"), +] + + +@pytest.mark.parametrize("model_key, fixture, expected_file", MODEL_CASES) +def test_parse_matches_golden(model_key, fixture, expected_file): + cls = device_registry[model_key] + raw = load(model_key, fixture) + + parsed = cls(raw).parse().model_dump(by_alias=True, mode="json") + + expected = json.loads((FIXTURES / model_key / expected_file).read_text("utf-8")) + assert parsed == expected + + +@pytest.mark.parametrize("model_key, fixture, _expected", MODEL_CASES) +def test_parse_has_required_sections(model_key, fixture, _expected): + cls = device_registry[model_key] + device = cls(load(model_key, fixture)).parse() + + assert device.system is not None + assert isinstance(device.interfaces, list) + assert isinstance(device.vlans, list)