コード例 #1
0
    def test_serialization_required_and_optional_attributes(self):
        """
        Test serialisation of Marktlokation with required attributes and optional attributes
        """
        gp = Geschaeftspartner(
            anrede=Anrede.FRAU,
            name1="von Sinnen",
            name2="Helga",
            name3=None,
            gewerbekennzeichnung=True,
            hrnummer="HRB 254466",
            amtsgericht="Amtsgericht München",
            kontaktweg=[Kontaktart.E_MAIL],
            umsatzsteuer_id="DE267311963",
            glaeubiger_id="DE98ZZZ09999999999",
            e_mail_adresse="*****@*****.**",
            website="bo4e.de",
            geschaeftspartnerrolle=[Geschaeftspartnerrolle.DIENSTLEISTER],
            partneradresse=Adresse(
                postleitzahl="82031",
                ort="Grünwald",
                strasse="Nördliche Münchner Straße",
                hausnummer="27A",
            ),
        )
        malo = Marktlokation(
            marktlokations_id="51238696781",
            sparte=Sparte.GAS,
            lokationsadresse=Adresse(postleitzahl="04177",
                                     ort="Leipzig",
                                     hausnummer="1",
                                     strasse="Jahnalle"),
            energierichtung=Energierichtung.EINSP,
            bilanzierungsmethode=Bilanzierungsmethode.PAUSCHAL,
            unterbrechbar=True,  # optional attribute
            netzebene=Netzebene.NSP,
            endkunde=gp,
        )
        assert malo.versionstruktur == "2", "versionstruktur was not automatically set"
        assert malo.bo_typ == BoTyp.MARKTLOKATION, "boTyp was not automatically set"

        schema = MarktlokationSchema()

        json_string = schema.dumps(malo, ensure_ascii=False)
        json_dict = json.loads(json_string)

        assert "boTyp" in json_dict, "No camel case serialization"
        assert "marktlokationsId" in json_dict, "No camel case serialization"

        deserialized_malo: Marktlokation = schema.loads(json_string)

        assert deserialized_malo.marktlokations_id == malo.marktlokations_id
        assert deserialized_malo.marktlokations_id is not malo.marktlokations_id
        assert deserialized_malo.bo_typ is BoTyp.MARKTLOKATION
        assert deserialized_malo.endkunde == gp
コード例 #2
0
    def test_serialization_strasse(self):
        """
        Test serialization with strasse und hausnummer
        and default value of landescode
        """
        with open(
            "./tests/test_data/test_data_adresse/test_data_adresse_only_required_fields.json",
            encoding="utf-8",
        ) as json_file:
            address_test_data = json.load(json_file)

        a = Adresse(
            postleitzahl=address_test_data["postleitzahl"],
            ort=address_test_data["ort"],
            strasse=address_test_data["strasse"],
            hausnummer=address_test_data["hausnummer"],
        )

        schema = AdresseSchema()
        address_dict = schema.dump(a)

        assert address_dict["strasse"] == "Nördliche Münchner Straße"
        assert address_dict["hausnummer"] == "27A"
        assert address_dict["postleitzahl"] == "82031"
        assert address_dict["landescode"] == "DE"

        deserialized_address = schema.load(address_dict)

        assert isinstance(deserialized_address, Adresse)
        assert deserialized_address.strasse == "Nördliche Münchner Straße"
        assert deserialized_address.hausnummer == "27A"
        assert deserialized_address.postleitzahl == "82031"
        assert deserialized_address.landescode == Landescode.DE
コード例 #3
0
    def test_serialization_only_postfach(self):
        """Test serialization with postfach"""
        address_test_data = {
            "postleitzahl": "82031",
            "ort": "Grünwald",
            "postfach": "10 64 38",
        }

        a = Adresse(
            postleitzahl=address_test_data["postleitzahl"],
            ort=address_test_data["ort"],
            postfach=address_test_data["postfach"],
        )

        schema = AdresseSchema()
        address_json = schema.dumps(a, ensure_ascii=False)

        assert "10 64 38" in address_json
        assert "82031" in address_json
        assert "DE" in address_json

        deserialized_address = schema.loads(address_json)

        assert isinstance(deserialized_address, Adresse)
        assert deserialized_address.postfach == "10 64 38"
        assert deserialized_address.postleitzahl == "82031"
        assert deserialized_address.landescode == Landescode.DE
コード例 #4
0
    def test_serialisation_only_required_attributes(self):
        """
        Test serialisation of Marktlokation only with required attributes
        """
        malo = Marktlokation(
            marktlokations_id="51238696781",
            sparte=Sparte.GAS,
            lokationsadresse=Adresse(postleitzahl="04177",
                                     ort="Leipzig",
                                     hausnummer="1",
                                     strasse="Jahnalle"),
            energierichtung=Energierichtung.EINSP,
            bilanzierungsmethode=Bilanzierungsmethode.PAUSCHAL,
            netzebene=Netzebene.NSP,
        )
        assert malo.versionstruktur == "2", "versionstruktur was not automatically set"
        assert malo.bo_typ is BoTyp.MARKTLOKATION, "boTyp was not automatically set"

        schema = MarktlokationSchema()

        json_string = schema.dumps(malo, ensure_ascii=False)
        json_dict = json.loads(json_string)

        assert "boTyp" in json_dict, "No camel case serialization"
        assert "marktlokationsId" in json_dict, "No camel case serialization"

        deserialized_malo: Marktlokation = schema.loads(json_string)

        # check that `deserialized_malo.marktlokations_id` and `malo.marktlokations_id` have the same value
        # but are **not** the same object.
        assert deserialized_malo.marktlokations_id == malo.marktlokations_id
        assert deserialized_malo.marktlokations_id is not malo.marktlokations_id
        assert deserialized_malo.bo_typ is BoTyp.MARKTLOKATION
コード例 #5
0
    def test_list_of_externe_referenz(self):
        gp = Geschaeftspartner(
            externe_referenzen=[
                ExterneReferenz(ex_ref_name="SAP GP Nummer",
                                ex_ref_wert="0123456789"),
                ExterneReferenz(ex_ref_name="Schufa-ID",
                                ex_ref_wert="aksdlakoeuhn"),
            ],
            # just some dummy data to make the GP valid
            name1="Duck",
            name2="Donald",
            gewerbekennzeichnung=False,
            geschaeftspartnerrolle=[Geschaeftspartnerrolle.KUNDE],
            partneradresse=Adresse(
                strasse="Am Geldspeicher",
                hausnummer="17",
                postleitzahl="88101",
                ort="Entenhausen",
            ),
        )

        schema = GeschaeftspartnerSchema()

        gp_json = schema.dumps(gp, ensure_ascii=False)

        deserialized_gp: Geschaeftspartner = schema.loads(gp_json)
        assert len(deserialized_gp.externe_referenzen) == 2
        assert deserialized_gp.externe_referenzen[
            0].ex_ref_name == "SAP GP Nummer"
コード例 #6
0
    def test_list_validation_of_geschaeftspartnerrolle(self):
        """
        Tests that if the geschaeftspartnerrolle of Geschaeftspartner is not a list, an error is raised.

        The attribute geschaeftspartnerrolle of Geschaeftspartner must be a list type.
        Therefore the list validator checks the type of geschaeftspartnerrolle
        during the initialization of Geschaeftspartner.
        """

        with pytest.raises(TypeError) as excinfo:

            _ = Geschaeftspartner(
                anrede=Anrede.FRAU,
                name1="von Sinnen",
                name2="Helga",
                name3=None,
                gewerbekennzeichnung=True,
                hrnummer="HRB 254466",
                amtsgericht="Amtsgericht München",
                kontaktweg=[Kontaktart.E_MAIL],
                umsatzsteuer_id="DE267311963",
                glaeubiger_id="DE98ZZZ09999999999",
                e_mail_adresse="*****@*****.**",
                website="bo4e.de",
                geschaeftspartnerrolle=Geschaeftspartnerrolle.DIENSTLEISTER,
                partneradresse=Adresse(
                    postleitzahl="01069",
                    ort="Dresden",
                    strasse="Goethestraße",
                    hausnummer="1",
                ),
            )

        assert "must be typing.List" in str(excinfo.value)
コード例 #7
0
    def test_strasse_xor_postfach(self, address_test_data, expected):

        with pytest.raises(ValueError) as excinfo:

            _ = Adresse(
                postleitzahl=address_test_data["postleitzahl"],
                ort=address_test_data["ort"],
                strasse=address_test_data["strasse"],
                hausnummer=address_test_data["hausnummer"],
                postfach=address_test_data["postfach"],
            )
        assert expected in str(excinfo.value)
コード例 #8
0
 def _instantiate_malo(malo_id: str):
     _ = Marktlokation(
         marktlokations_id=malo_id,
         sparte=Sparte.GAS,
         lokationsadresse=Adresse(
             postleitzahl="82031",
             ort="Grünwald",
             hausnummer="27A",
             strasse="Nördliche Münchner Straße",
         ),
         energierichtung=Energierichtung.EINSP,
         bilanzierungsmethode=Bilanzierungsmethode.PAUSCHAL,
         unterbrechbar=True,
         netzebene=Netzebene.NSP,
     )
コード例 #9
0
    def test_missing_required_attribute(self, datafiles):
        """
        Test for getting an error message if a required attribute is missing
        """
        with open(datafiles / "test_data_adresse_missing_plz.json", encoding="utf-8") as json_file:
            address_test_data = json.load(json_file)

        with pytest.raises(TypeError) as excinfo:

            _ = Adresse(
                ort=address_test_data["ort"],
                strasse=address_test_data["strasse"],
                hausnummer=address_test_data["hausnummer"],
            )

        assert "postleitzahl" in str(excinfo.value)
コード例 #10
0
    def test_serialization_only_required_fields_landescode_AT(self):
        with open(
            "./tests/test_data/test_data_adresse/test_data_adresse_only_required_fields.json",
            encoding="utf-8",
        ) as json_file:
            address_test_data = json.load(json_file)

        a = Adresse(
            postleitzahl=address_test_data["postleitzahl"],
            ort=address_test_data["ort"],
            strasse=address_test_data["strasse"],
            hausnummer=address_test_data["hausnummer"],
            landescode=Landescode.AT,
        )

        schema = AdresseSchema()
        address_json = schema.dumps(a, ensure_ascii=False)
        deserialized_address = schema.loads(address_json)

        assert deserialized_address.landescode == Landescode.AT
コード例 #11
0
    def test_serializable(self, datafiles):

        with open(datafiles / "test_data_adresse_only_required_fields.json",
                  encoding="utf-8") as json_file:
            address_test_data = json.load(json_file)

        gp = Geschaeftspartner(
            anrede=Anrede.FRAU,
            name1="von Sinnen",
            name2="Helga",
            name3=None,
            gewerbekennzeichnung=True,
            hrnummer="HRB 254466",
            amtsgericht="Amtsgericht München",
            kontaktweg=[Kontaktart.E_MAIL],
            umsatzsteuer_id="DE267311963",
            glaeubiger_id="DE98ZZZ09999999999",
            e_mail_adresse="*****@*****.**",
            website="bo4e.de",
            geschaeftspartnerrolle=[Geschaeftspartnerrolle.DIENSTLEISTER],
            partneradresse=Adresse(
                postleitzahl=address_test_data["postleitzahl"],
                ort=address_test_data["ort"],
                strasse=address_test_data["strasse"],
                hausnummer=address_test_data["hausnummer"],
            ),
        )

        # test default value for bo_typ in Geschaeftspartner
        assert gp.bo_typ == BoTyp.GESCHAEFTSPARTNER

        schema = GeschaeftspartnerSchema()

        gp_json = schema.dumps(gp, ensure_ascii=False)

        assert "Helga" in gp_json

        gp_deserialised = schema.loads(gp_json)

        assert gp_deserialised.bo_typ == gp.bo_typ
        assert type(gp_deserialised.partneradresse) == Adresse
コード例 #12
0
    def test_address_validation(self):
        with pytest.raises(ValueError) as excinfo:
            _ = Marktlokation(
                marktlokations_id="51238696781",
                sparte=Sparte.GAS,
                lokationsadresse=Adresse(
                    postleitzahl="04177",
                    ort="Leipzig",
                    hausnummer="1",
                    strasse="Jahnalle",
                ),
                energierichtung=Energierichtung.EINSP,
                bilanzierungsmethode=Bilanzierungsmethode.PAUSCHAL,
                unterbrechbar=True,  # optional attribute
                netzebene=Netzebene.NSP,
                geoadresse="test",
                katasterinformation="test",
            )

        assert "No or more than one address information is given." == str(
            excinfo.value)
コード例 #13
0
    def test_geschaeftspartner_with_no_externe_referenz(self):
        gp = Geschaeftspartner(
            # just some dummy data to make the GP valid
            name1="Duck",
            name2="Donald",
            gewerbekennzeichnung=False,
            geschaeftspartnerrolle=[Geschaeftspartnerrolle.KUNDE],
            partneradresse=Adresse(
                strasse="Am Geldspeicher",
                hausnummer="17",
                postleitzahl="88101",
                ort="Entenhausen",
            ),
        )

        schema = GeschaeftspartnerSchema()

        gp_json = schema.dumps(gp, ensure_ascii=False)

        deserialized_gp: Geschaeftspartner = schema.loads(gp_json)

        assert deserialized_gp.externe_referenzen == []
コード例 #14
0
    def test_serialization_only_required_fields(self):
        """Test serialization with just postleitzahl und ort"""
        address_test_data = {
            "postleitzahl": "82031",
            "ort": "Grünwald",
        }

        a = Adresse(
            postleitzahl=address_test_data["postleitzahl"],
            ort=address_test_data["ort"],
        )

        schema = AdresseSchema()
        address_json = schema.dumps(a, ensure_ascii=False)

        assert "Grünwald" in address_json
        assert "82031" in address_json

        deserialized_address = schema.loads(address_json)

        assert isinstance(deserialized_address, Adresse)
        assert deserialized_address.ort == "Grünwald"
        assert deserialized_address.postleitzahl == "82031"