Skip to content

Commit

Permalink
✅Test Zeitreihenwert
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-sheese committed Nov 8, 2023
1 parent 9e4af75 commit 8df73e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 42 deletions.
3 changes: 1 addition & 2 deletions tests/test_zeitreihe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from bo4e import Medium, Mengeneinheit, Messart, Messgroesse, Wertermittlungsverfahren, Zeitreihe
from tests.serialization_helper import assert_serialization_roundtrip
from tests.test_zeitreihenwert import example_zeitreihenwert


class TestZeitreihe:
Expand All @@ -20,7 +19,7 @@ class TestZeitreihe:
medium=Medium.STROM,
einheit=Mengeneinheit.KVARH,
wertherkunft=Wertermittlungsverfahren.MESSUNG,
werte=[example_zeitreihenwert],
werte=[],
)
),
],
Expand Down
58 changes: 18 additions & 40 deletions tests/test_zeitreihenwert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,26 @@
from pydantic import ValidationError

from bo4e import Messwertstatus, Messwertstatuszusatz, Zeitreihenwert

example_zeitreihenwert = Zeitreihenwert(
wert=Decimal(2.5),
datum_uhrzeit_von=datetime(2001, 3, 15, tzinfo=timezone.utc),
datum_uhrzeit_bis=datetime(2007, 11, 27, tzinfo=timezone.utc),
)
from tests.serialization_helper import assert_serialization_roundtrip


class TestZeitreihenwert:
def test_zeitreihenwert_only_required_attributes(self) -> None:
"""
Test de-/serialisation of Zeitreihenwert with minimal attributes.
"""
zeitreihenwert = example_zeitreihenwert

json_string = zeitreihenwert.model_dump_json(by_alias=True)

assert "2001-03-15T00:00:00Z" in json_string
assert "2007-11-27T00:00:00Z" in json_string

zeitreihenwert_deserialized: Zeitreihenwert = Zeitreihenwert.model_validate_json(json_string)
assert zeitreihenwert_deserialized == zeitreihenwert

def test_zeitreihenwert_required_and_optional_attributes(self) -> None:
@pytest.mark.parametrize(
"zeitreihenwert",
[
pytest.param(
Zeitreihenwert(
datum_uhrzeit_von=datetime(2001, 3, 15, tzinfo=timezone.utc),
datum_uhrzeit_bis=datetime(2007, 11, 27, tzinfo=timezone.utc),
wert=Decimal(2.5),
status=Messwertstatus.ABGELESEN,
statuszusatz=Messwertstatuszusatz.Z78_GERAETEWECHSEL,
),
),
],
)
def test_serialization_roundtrip(self, zeitreihenwert: Zeitreihenwert) -> None:
"""
Test de-/serialisation of Zeitreihenwert with maximal attributes.
Test de-/serialisation of Zeitreihenwert.
"""
zeitreihenwert = Zeitreihenwert(
datum_uhrzeit_von=datetime(2001, 3, 15, tzinfo=timezone.utc),
datum_uhrzeit_bis=datetime(2007, 11, 27, tzinfo=timezone.utc),
wert=Decimal(2.5),
status=Messwertstatus.ABGELESEN,
statuszusatz=Messwertstatuszusatz.Z78_GERAETEWECHSEL,
)

json_string = zeitreihenwert.model_dump_json(by_alias=True)

assert "2.5" in json_string
assert "2001-03-15T00:00:00Z" in json_string
assert "2007-11-27T00:00:00Z" in json_string
assert "ABGELESEN" in json_string
assert "Z78_GERAETEWECHSEL" in json_string

zeitreihenwert_deserialized: Zeitreihenwert = Zeitreihenwert.model_validate_json(json_string)
assert zeitreihenwert_deserialized == zeitreihenwert
assert_serialization_roundtrip(zeitreihenwert)

0 comments on commit 8df73e2

Please sign in to comment.