-
Notifications
You must be signed in to change notification settings - Fork 5
Implement BO Tarifkosten #331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||
| """ | ||||||
| Contains Tarifkosten class | ||||||
| and corresponding marshmallow schema for de-/serialization | ||||||
| """ | ||||||
| import attr | ||||||
| from marshmallow import fields | ||||||
|
|
||||||
| from bo4e.bo.kosten import Kosten, KostenSchema | ||||||
| from bo4e.bo.tarifinfo import Tarifinfo, TarifinfoSchema | ||||||
| from bo4e.enum.botyp import BoTyp | ||||||
|
|
||||||
|
|
||||||
| # pylint: disable=too-few-public-methods | ||||||
| @attr.s(auto_attribs=True, kw_only=True) | ||||||
| class Tarifkosten(Tarifinfo): | ||||||
| """ | ||||||
| Objekt zur Kommunikation von Kosten, die im Rahmen der Tarifanwendung entstehen | ||||||
| """ | ||||||
|
|
||||||
| # required attributes | ||||||
| bo_typ: BoTyp = attr.ib(default=BoTyp.TARIFKOSTEN) | ||||||
| kosten: Kosten = attr.ib(validator=attr.validators.instance_of(Kosten)) | ||||||
| """ | ||||||
| Referenz (Link) zu einem Kostenobjekt, in dem die Kosten für die Anwendung | ||||||
| des Tarifs auf eine Abnahmesituation berechnet wurden | ||||||
| """ | ||||||
|
|
||||||
| # there are no optional attributes | ||||||
|
|
||||||
|
|
||||||
| class TarifkostenSchema(TarifinfoSchema): | ||||||
| """ | ||||||
| Schema for de-/serialization of Tarifkosten. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| """ | ||||||
|
|
||||||
| # class_name is needed to use the correct schema for deserialization. | ||||||
| # see function `deserialize` in geschaeftsobjekt.py | ||||||
| class_name = Tarifkosten # type:ignore[assignment] | ||||||
|
|
||||||
| # required attributes | ||||||
| kosten = fields.Nested(KostenSchema) | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import pytest # type:ignore[import] | ||
|
|
||
| from bo4e.bo.tarifkosten import Tarifkosten, TarifkostenSchema | ||
| from bo4e.enum.kundentyp import Kundentyp | ||
| from bo4e.enum.sparte import Sparte | ||
| from bo4e.enum.tarifart import Tarifart | ||
| from bo4e.enum.tarifmerkmal import Tarifmerkmal | ||
| from bo4e.enum.tariftyp import Tariftyp | ||
| from tests.serialization_helper import assert_serialization_roundtrip # type:ignore[import] | ||
| from tests.test_energiemix import example_energiemix # type:ignore[import] | ||
| from tests.test_kosten import example_kosten # type:ignore[import] | ||
| from tests.test_marktteilnehmer import example_marktteilnehmer # type:ignore[import] | ||
| from tests.test_vertragskonditionen import example_vertragskonditionen # type:ignore[import] | ||
| from tests.test_zeitraum import example_zeitraum # type:ignore[import] | ||
|
|
||
|
|
||
| class TestTarifkosten: | ||
| @pytest.mark.parametrize( | ||
| "tarifkosten", | ||
| [ | ||
| pytest.param( | ||
| Tarifkosten( | ||
| bezeichnung="foo", | ||
| anbietername="der beste stromanbieter", | ||
| sparte=Sparte.STROM, | ||
| kundentypen=[Kundentyp.PRIVAT, Kundentyp.GEWERBE], | ||
| tarifart=Tarifart.MEHRTARIF, | ||
| tariftyp=Tariftyp.GRUND_ERSATZVERSORGUNG, | ||
| tarifmerkmale=[Tarifmerkmal.HEIZSTROM], | ||
| website="https://foo.inv", | ||
| bemerkung="super billig aber auch super dreckig", | ||
| vertragskonditionen=example_vertragskonditionen, | ||
| zeitliche_gueltigkeit=example_zeitraum, | ||
| energiemix=example_energiemix, | ||
| anbieter=example_marktteilnehmer, | ||
| kosten=example_kosten, | ||
| ) | ||
| ), | ||
| ], | ||
| ) | ||
| def test_serialization_roundtrip(self, tarifkosten: Tarifkosten): | ||
| """ | ||
| Test de-/serialisation | ||
| """ | ||
| assert_serialization_roundtrip(tarifkosten, TarifkostenSchema()) | ||
|
|
||
| def test_missing_required_attribute(self): | ||
| with pytest.raises(TypeError) as excinfo: | ||
| _ = Tarifkosten() | ||
|
|
||
| assert "missing 9 required" in str(excinfo.value) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ja, das steht in der doku, aber für uns macht das keinen Sinn/keinen Unterscheid