Example #1
0
    def test_money_division_by_zero(self):
        """
        Test that dividing Money object by zero throws ZeroDivisionError exception

        """
        with pt.raises(ZeroDivisionError):
            assert self.money / Money("0")
Example #2
0
    def test_money_multiplication_method(self, amount):
        """
        Test the multiplication method of Money object

        """
        correct_mul = str(
            Decimal(self.money.amount.replace(" ", "")) * Decimal(amount))
        assert (self.money * Money(amount)).replace(" ", "") == correct_mul
Example #3
0
    def test_money_true_division_method(self, amount):
        """
        Test the division method of Money object

        """
        correct_mul = str(
            Decimal(self.money.amount.replace(" ", "")) / Decimal(amount))
        assert (self.money / Money(amount)).replace(" ", "") == correct_mul
Example #4
0
    def test_money_subtracting_method(self, amount):
        """
        Testing subtracting two amounts together

        """
        correct_sum = str(
            Decimal(self.money.amount.replace(" ", "")) -
            Decimal(amount)) + "kr"
        assert str(self.money - Money(amount)).replace(" ", "") == correct_sum
Example #5
0
    def test_money_adding_method(self, amount):
        """
        Testing adding two amounts together in Money object

        """
        correct_sum = str(
            Decimal(self.money.amount.replace(" ", "")) +
            Decimal(amount)) + "kr"
        assert str(self.money + Money(amount)).replace(" ", "") == correct_sum
Example #6
0
    def test_money_throws_type_error_for_invalid_argument_types(
            self, invalid_money_type):
        """
        Test that TypeError is thrown if invalid type, i.e. not str is passed to Money object

        """
        with pt.raises(TypeError):
            Money(invalid_money_type)
        with pt.raises(TypeError):
            self.money.amount = invalid_money_type
Example #7
0
    def calculate_yearly_income(self, monthly_income: str):
        """
        method for calculating / setting / formatting yearly gross income

        Parameters
        ----------
        monthly_income  : str

        """
        Assertor.assert_data_types([monthly_income], [str])
        yearly_income = self.parent.ui.line_edit_brutto_arsinntekt.text()
        if monthly_income and not yearly_income:
            yearly_income_from_monthly = Money(
                str(
                    Decimal(
                        monthly_income.replace(" kr", "").replace(" ", "")) *
                    12))
            self.data.update(
                {"brutto_arsinntekt": yearly_income_from_monthly.value()})
            return yearly_income_from_monthly.value()
        else:
            return yearly_income
Example #8
0
 def calculate_monthly_values(self, line_edit: str, value: str,
                              factor: str):
     Assertor.assert_data_types([value, factor], [str, str])
     if value and factor:
         quantity = Decimal(value.replace(" ", "").replace(
             "kr", "")) * Decimal(
                 factor.replace(" ", "").replace("kr", ""))
         divisor = Decimal("12")
         monthly_values = round(Decimal(quantity / divisor))
         self.data.update({line_edit: Money(str(monthly_values)).value()})
     elif value:
         monthly_values = round(
             Decimal(value.replace(" ", "").replace("kr", "")))
     else:
         monthly_values = round(Decimal("0"))
     return monthly_values
Example #9
0
    def tax_information(self):
        """
        method for getting tax dict given information passed to class

        Returns
        -------
        out     : dict
                  tax information given information passed through class

        """
        tax_dict = self.response().json()
        tax_info = {}

        for keys, values in tax_dict.items():
            if keys == "hovedperson":
                for key, value in values.items():
                    if key == "beregnetSkattV4":
                        for tag, val in value.items():
                            if tag == "skatteklasse":
                                tax_info.update({tag: val})
                            elif tag == "skatteregnskapskommune":
                                tax_info.update({tag: val})
                            elif tag == "informasjonTilSkattelister":
                                tax_info.update({
                                    "nettoinntekt":
                                    Money(str(val["nettoinntekt"])).value()
                                })
                                tax_info.update({
                                    "nettoformue":
                                    Money(str(val["nettoformue"])).value()
                                })
                                tax_info.update({
                                    "beregnetSkatt":
                                    Money(str(val["beregnetSkatt"])).value()
                                })
                            elif tag == "beregnetSkattFoerSkattefradrag":
                                tax_info.update({
                                    tag: {
                                        "grunnlag":
                                        Money(str(val["grunnlag"])).value(),
                                        "beloep":
                                        Money(str(val["beloep"])).value()
                                    }
                                })
                            elif tag == "beregnetSkatt":
                                tax_info.update({
                                    tag: {
                                        "grunnlag":
                                        Money(str(val["grunnlag"])).value(),
                                        "beloep":
                                        Money(str(val["beloep"])).value()
                                    }
                                })
                            elif tag == "skattOgAvgift":
                                for sub_tag, sub_val in val.items():
                                    if sub_tag in [
                                            "formuesskattTilStat",
                                            "inntektsskattTilKommune",
                                            "inntektsskattTilFylkeskommune",
                                            "inntektsskattTilKommuneOgFylkeskommune",
                                            "formuesskattTilKommune",
                                            "fellesskatt", "trinnskatt",
                                            "trygdeavgiftAvLoennsinntekt",
                                            "sumTrygdeavgift"
                                    ]:
                                        tax_info.update({
                                            sub_tag: {
                                                "grunnlag":
                                                Money(str(sub_val["grunnlag"])
                                                      ).value(),
                                                "beloep":
                                                Money(str(sub_val["beloep"])).
                                                value()
                                            }
                                        })
                    elif key == "beregningsgrunnlagV4":
                        for tag, val in value.items():
                            if tag == "beregningsgrunnlagsobjekt":
                                for element in val:
                                    tax_info.update({
                                        element["tekniskNavn"]:
                                        Money(str(element["beloep"])).value()
                                    })
                    elif key == "summertSkattegrunnlagForVisningV7":
                        for tag, val in value.items():
                            if tag == "skattegrunnlagsobjekt":
                                for element in val:
                                    tax_info.update({
                                        element["tekniskNavn"]:
                                        Money(str(element["beloep"])).value()
                                    })
        return tax_info
Example #10
0
    def monthly_value(self):
        parent = self.parent.ui
        brutto_income_1 = self.calculate_monthly_values(
            "brutto_inntekt_1", parent.line_edit_brutto_inntekt_1.text(),
            self._intervall[parent.combo_box_interval_1.currentText()])
        trygd_income_1 = self.calculate_monthly_values(
            "trygde_inntekt_1", parent.line_edit_trygde_inntekt_1.text(),
            self._intervall[parent.combo_box_interval_2.currentText()])
        leie_income_1 = self.calculate_monthly_values(
            "leieinntekt_1", parent.line_edit_leieinntekt_1.text(),
            self._intervall[parent.combo_box_interval_3.currentText()])
        other_income_1 = self.calculate_monthly_values(
            "andre_inntekter_1", parent.line_edit_andre_inntekter_1.text(),
            self._intervall[parent.combo_box_interval_4.currentText()])

        sum_income_1 = brutto_income_1 + trygd_income_1 + leie_income_1 + other_income_1
        person_income_1 = Money(
            str(sum_income_1)).value() if sum_income_1 != 0 else ""
        parent.line_edit_personinntekt_1.setText(person_income_1)
        self.set_line_edit("personinntekt_1", data=person_income_1)

        brutto_income_2 = self.calculate_monthly_values(
            "brutto_inntekt_2", parent.line_edit_brutto_inntekt_2.text(),
            self._intervall[parent.combo_box_interval_10.currentText()])
        trygd_income_2 = self.calculate_monthly_values(
            "trygde_inntekt_2", parent.line_edit_trygde_inntekt_2.text(),
            self._intervall[parent.combo_box_interval_11.currentText()])
        leie_income_2 = self.calculate_monthly_values(
            "leieinntekt_2", parent.line_edit_leieinntekt_2.text(),
            self._intervall[parent.combo_box_interval_12.currentText()])
        other_income_2 = self.calculate_monthly_values(
            "andre_inntekter_2", parent.line_edit_andre_inntekter_2.text(),
            self._intervall[parent.combo_box_interval_13.currentText()])

        sum_income_2 = brutto_income_2 + trygd_income_2 + leie_income_2 + other_income_2
        person_income_2 = Money(
            str(sum_income_2)).value() if sum_income_2 != 0 else ""
        parent.line_edit_personinntekt_2.setText(person_income_2)
        self.set_line_edit("personinntekt_2", data=person_income_2)

        student_loan_1 = self.calculate_monthly_values(
            "student_lan_1", parent.line_edit_student_lan_1.text(),
            self._intervall[parent.combo_box_interval_5.currentText()])
        credit_debt_1 = self.calculate_monthly_values(
            "kreditt_gjeld_1", parent.line_edit_kreditt_gjeld_1.text(),
            self._intervall[parent.combo_box_interval_6.currentText()])
        housing_rent_1 = self.calculate_monthly_values(
            "husleie_1", parent.line_edit_husleie_1.text(),
            self._intervall[parent.combo_box_interval_7.currentText()])
        power_1 = self.calculate_monthly_values(
            "strom_1", parent.line_edit_strom_1.text(),
            self._intervall[parent.combo_box_interval_8.currentText()])
        other_1 = self.calculate_monthly_values(
            "andre_utgifter_1", parent.line_edit_andre_utgifter_1.text(),
            self._intervall[parent.combo_box_interval_9.currentText()])

        sum_expenses_1 = student_loan_1 + credit_debt_1 + housing_rent_1 + power_1 + other_1
        person_expenses_1 = Money(
            str(sum_expenses_1)).value() if sum_expenses_1 != 0 else ""
        parent.line_edit_sum_utgifter_1.setText(person_expenses_1)
        self.set_line_edit("sum_utgifter_1", data=person_expenses_1)

        student_loan_2 = self.calculate_monthly_values(
            "student_lan_2", parent.line_edit_student_lan_2.text(),
            self._intervall[parent.combo_box_interval_14.currentText()])
        credit_debt_2 = self.calculate_monthly_values(
            "kreditt_gjeld_2", parent.line_edit_kreditt_gjeld_2.text(),
            self._intervall[parent.combo_box_interval_15.currentText()])
        housing_rent_2 = self.calculate_monthly_values(
            "husleie_2", parent.line_edit_husleie_2.text(),
            self._intervall[parent.combo_box_interval_16.currentText()])
        power_2 = self.calculate_monthly_values(
            "strom_2", parent.line_edit_strom_2.text(),
            self._intervall[parent.combo_box_interval_17.currentText()])
        other_2 = self.calculate_monthly_values(
            "andre_utgifter_2", parent.line_edit_andre_utgifter_2.text(),
            self._intervall[parent.combo_box_interval_18.currentText()])

        sum_expenses_2 = student_loan_2 + credit_debt_2 + housing_rent_2 + power_2 + other_2
        person_expenses_2 = Money(
            str(sum_expenses_2)).value() if sum_expenses_2 != 0 else ""
        parent.line_edit_sum_utgifter_2.setText(person_expenses_2)
        self.set_line_edit("sum_utgifter_2", data=person_expenses_2)
Example #11
0
    def test_money_value_object_not_equal(self):
        """
        Testing that two Money Value objects are not equal when all properties are not equal

        """
        assert self.money != Money("90211")
Example #12
0
    def setup(cls):
        """
        Executed before all tests

        """
        cls.money = Money("90210")