Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/bo4e/com/preis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ class Preis(COM):
"""

# required attributes
#: Gibt die nomiale Höhe des Preises an.
wert: Decimal = attr.ib(validator=attr.validators.instance_of(Decimal))
#: Währungseinheit für den Preis, z.B. Euro oder Ct.
einheit: Waehrungseinheit = attr.ib(validator=attr.validators.in_(Waehrungseinheit))
#: Angabe, für welche Bezugsgröße der Preis gilt. Z.B. kWh.
bezugswert: Mengeneinheit = attr.ib(validator=attr.validators.in_(Mengeneinheit))

# optional attributes
#: Gibt den Status des veröffentlichten Preises an
status: Optional[Preisstatus] = attr.ib(default=None)


Expand Down
14 changes: 9 additions & 5 deletions tests/test_preis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def test_preis_only_required(self):
"""
Test de-/serialisation of Preis (only has required attributes).
"""
preis = Preis(
wert=Decimal(2.53), einheit=Waehrungseinheit.EUR, bezugswert=Mengeneinheit.KWH
)
preis = Preis(wert=Decimal(2.53), einheit=Waehrungseinheit.EUR, bezugswert=Mengeneinheit.KWH)

schema = PreisSchema()
json_string = schema.dumps(preis, ensure_ascii=False)
Expand All @@ -29,7 +27,8 @@ def test_preis_only_required(self):
assert isinstance(preis_deserialized.wert, Decimal)
assert isinstance(preis_deserialized.einheit, Waehrungseinheit)
assert isinstance(preis_deserialized.bezugswert, Mengeneinheit)
assert not preis_deserialized.status
assert preis_deserialized.status is None
assert preis == preis_deserialized

def test_wrong_datatype(self):
with pytest.raises(TypeError) as excinfo:
Expand All @@ -44,7 +43,12 @@ def test_missing_required_attribute(self):
assert "missing 1 required" in str(excinfo.value)

def test_optional_attribute(self):
preis = Preis(wert=Decimal(3.50), einheit=Waehrungseinheit.EUR, bezugswert=Mengeneinheit.KWH, status=Preisstatus.ENDGUELTIG)
preis = Preis(
wert=Decimal(3.50),
einheit=Waehrungseinheit.EUR,
bezugswert=Mengeneinheit.KWH,
status=Preisstatus.ENDGUELTIG,
)

schema = PreisSchema()
json_string = schema.dumps(preis, ensure_ascii=False)
Expand Down