From 9b098be72adcd3cb72b3c812fd2af39a1bc18d69 Mon Sep 17 00:00:00 2001 From: Ardt Klapwijk <59741981+ArdtK@users.noreply.github.com> Date: Fri, 19 Jul 2024 21:43:29 +0200 Subject: [PATCH] test: add unittest for serializing list --- tests/models/test_base_model.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/models/test_base_model.py b/tests/models/test_base_model.py index e0a2377e..9d653aac 100644 --- a/tests/models/test_base_model.py +++ b/tests/models/test_base_model.py @@ -6,6 +6,7 @@ from fastapi.testclient import TestClient from teamcity import is_running_under_teamcity +from geolib._compat import IS_PYDANTIC_V2 from geolib.models import BaseDataClass, DSettlementModel from geolib.models.base_model import BaseModel, BaseModelList, MetaData from geolib.models.dfoundations.dfoundations_model import DFoundationsModel @@ -104,6 +105,24 @@ def test_basemodellist_execute(self, model, filename, modelname): assert len(output.errors) == 1 assert fn in output.errors[-1] + @pytest.mark.unittest + def test_serialize_modellist(self): + # 1. Set initial test data. + a = DSettlementModel(filename="a.txt") + b = DSettlementModel(filename="b.txt") + ml = BaseModelList(models=[a, b]) + + # 2. Define test action. + if IS_PYDANTIC_V2: + _dump = ml.model_dump() + else: + _dump = ml.dict() + + # 3. Verify final expectations. + assert _dump.get("models") == [a.model_dump(), b.model_dump()] + for _model in _dump.get("models"): + assert _model["datastructure"] + @pytest.mark.acceptance @only_teamcity @mock.patch("geolib.models.base_model.requests.post", side_effect=client.post)