Skip to content

Commit

Permalink
test: add unittest for serializing list
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdtK committed Jul 19, 2024
1 parent c5f43ca commit 9b098be
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/models/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9b098be

Please sign in to comment.