dev #5
@@ -23,7 +23,7 @@ class ModelView(Generic[TModel]):
|
|||||||
def dump_json(self) -> str:
|
def dump_json(self) -> str:
|
||||||
if isinstance(self._model, list):
|
if isinstance(self._model, list):
|
||||||
return json.dumps(
|
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,
|
ensure_ascii=False,
|
||||||
)
|
)
|
||||||
return self._model.model_dump_json(by_alias=True)
|
return self._model.model_dump_json(by_alias=True)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from ipaddress import IPv4Address
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -66,6 +67,10 @@ class TestListModelView:
|
|||||||
def test_dump_uses_aliases(self, interfaces_view):
|
def test_dump_uses_aliases(self, interfaces_view):
|
||||||
dumped = interfaces_view.dump()
|
dumped = interfaces_view.dump()
|
||||||
assert dumped[0]["interface"] == "eth0"
|
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):
|
def test_dump_json_keeps_unicode(self):
|
||||||
view = ModelView([Interfaces(interface="eth0", description="Дом")])
|
view = ModelView([Interfaces(interface="eth0", description="Дом")])
|
||||||
|
|||||||
Reference in New Issue
Block a user