From 663cbad352e50c8173de8307f84da03dcb809345 Mon Sep 17 00:00:00 2001 From: sttarsky <152534446+sttarsky@users.noreply.github.com> Date: Wed, 15 Jul 2026 16:01:21 +0300 Subject: [PATCH 1/3] Bump version from 0.1.1 to 0.1.2 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c497e2d..a1dfe88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "oxipy" -version = "0.1.1" +version = "0.1.2" description = "Python client for Oxidized API with TTP-based config parsing" readme = "README.md" license = "Apache-2.0" From 260c02f81dedcb6cfff1aa13f70cdc99a62974e8 Mon Sep 17 00:00:00 2001 From: IluaAir Date: Thu, 23 Jul 2026 10:24:51 +0300 Subject: [PATCH 2/3] Add type hints and docstrings for VLANs, Interfaces, and System properties in NodeConfig - Enhanced the `vlans`, `interfaces`, and `system` properties with type hints for better clarity and type checking. - Added detailed docstrings to each property, describing the return types and structure of the associated configurations. --- oxi/conf.py | 38 +++++++++++++++++++++++++++++++++++--- pyproject.toml | 2 +- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/oxi/conf.py b/oxi/conf.py index d354396..7ed2fb2 100644 --- a/oxi/conf.py +++ b/oxi/conf.py @@ -10,6 +10,9 @@ from .interfaces import BaseDevice, device_registry if TYPE_CHECKING: from requests import Session + from oxi.interfaces.contract import Interfaces, System, Vlans + + TModel = TypeVar("TModel", bound=BaseModel) @@ -83,13 +86,42 @@ class NodeConfig: return self.text @property - def vlans(self): + def vlans(self) -> list["Vlans"]: + """ + Returns the list of VLAN configurations for the node. + + :return: List of Vlans associated with the device. + vlan_id: int + name: str | None = Field(default=None, alias="description") + :rtype: list[oxi.interfaces.contract.Vlans] + """ + return ModelView(self._parsed_data.vlans) return ModelView(self._parsed_data.vlans) @property - def interfaces(self): + def interfaces(self) -> list["Interfaces"]: + """ + Returns the list of Interfaces configurations for the node. + + :return: List of Interfaces associated with the device. + name: str = Field(alias="interface") + ip_address: IPv4Address | None = None + mask: int | None = None + description: str | None = None + shutdown: bool = False + :rtype: list[oxi.interfaces.contract.Interfaces] + """ return ModelView(self._parsed_data.interfaces) @property - def system(self): + def system(self) -> "System": + """ + Returns the Systems configurations for the node. + + :return: System associated with the device. + model: str + serial_number: str + version: str + :rtype: oxi.interfaces.contract.System + """ return ModelView(self._parsed_data.system) diff --git a/pyproject.toml b/pyproject.toml index 9b9700f..78d1692 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "oxipy" -version = "0.1.3" +version = "0.1.4" description = "Python client for Oxidized API with TTP-based config parsing" readme = "README.md" license = "Apache-2.0" From ae1e69d5fd4246f4630d18fccde319153f8ab18f Mon Sep 17 00:00:00 2001 From: IluaAir Date: Thu, 23 Jul 2026 11:15:10 +0300 Subject: [PATCH 3/3] Refactor dump_json method to use model_dump_json - Fix the `dump_json` method in the `ModelView` class to call `model_dump_json` instead of `model_dump`, ensuring consistency in JSON serialization. - Added a new test case in `TestListModelView` to verify the functionality of `dump_json` and check for correct IP address serialization. --- oxi/conf.py | 2 +- tests/test_view.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/oxi/conf.py b/oxi/conf.py index 7ed2fb2..d0a798d 100644 --- a/oxi/conf.py +++ b/oxi/conf.py @@ -23,7 +23,7 @@ class ModelView(Generic[TModel]): def dump_json(self) -> str: if isinstance(self._model, list): return json.dumps( - [item.model_dump(by_alias=True) for item in self._model], + [item.model_dump_json(by_alias=True) for item in self._model], ensure_ascii=False, ) return self._model.model_dump_json(by_alias=True) diff --git a/tests/test_view.py b/tests/test_view.py index ea38ac8..a3b581f 100644 --- a/tests/test_view.py +++ b/tests/test_view.py @@ -1,4 +1,5 @@ import json +from ipaddress import IPv4Address import pytest @@ -66,6 +67,10 @@ class TestListModelView: def test_dump_uses_aliases(self, interfaces_view): dumped = interfaces_view.dump() assert dumped[0]["interface"] == "eth0" + assert dumped[0]["ip_address"] == IPv4Address("192.168.1.1") + + def test_dump_json(self, interfaces_view): + assert interfaces_view.dump_json() def test_dump_json_keeps_unicode(self): view = ModelView([Interfaces(interface="eth0", description="Дом")])