def test_sum_check_invalid_raises_ValidationError(conditions,
                                                  calculation_total,
                                                  target_total, error_type,
                                                  mock_form):
    validator = SumCheck()

    with pytest.raises(ValidationError) as exc:
        validator(mock_form, conditions, calculation_total, target_total)

    assert error_messages[error_type] % {
        "total": format_playback_value(target_total)
    } == str(exc.value)
def test_currency_playback(mock_form):
    validator = SumCheck(currency="EUR")

    conditions = ["equals"]
    calculation_total = 10
    target_total = 11.5

    with pytest.raises(ValidationError) as exc:
        validator(mock_form, conditions, calculation_total, target_total)

    assert (error_messages["TOTAL_SUM_NOT_EQUALS"] % {
        "total": format_playback_value(target_total, currency="EUR"),
    } == str(exc.value))
    def test_greater_or_equal_condition_check(self):
        validator = SumCheck()

        mock_form = Mock()

        conditions = ["greater than", "equals"]
        calculation_total = 11.99
        target_total = 12.5

        with self.assertRaises(ValidationError) as ite:
            validator(mock_form, conditions, calculation_total, target_total)

        self.assertEqual(
            error_messages["TOTAL_SUM_NOT_GREATER_THAN_OR_EQUALS"] %
            dict(total=format_playback_value(target_total)),
            str(ite.exception),
        )
    def test_less_than_condition_check(self):
        validator = SumCheck()

        mock_form = Mock()

        conditions = ["less than"]
        calculation_total = 11.99
        target_total = 11.5

        with self.assertRaises(ValidationError) as ite:
            validator(mock_form, conditions, calculation_total, target_total)

        self.assertEqual(
            error_messages["TOTAL_SUM_NOT_LESS_THAN"] %
            dict(total=format_playback_value(target_total)),
            str(ite.exception),
        )
    def test_currency_playback(self):
        validator = SumCheck(currency="EUR")

        mock_form = Mock()

        conditions = ["equals"]
        calculation_total = 10
        target_total = 11.5

        with self.assertRaises(ValidationError) as ite:
            validator(mock_form, conditions, calculation_total, target_total)

        self.assertEqual(
            error_messages["TOTAL_SUM_NOT_EQUALS"] %
            dict(total=format_playback_value(target_total, currency="EUR")),
            str(ite.exception),
        )
Пример #6
0
    def test_less_or_equal_condition_check(self):
        validator = SumCheck()

        mock_form = Mock()

        conditions = ["less than", "equals"]
        calculation_total = 20
        target_total = 11.5

        with self.assertRaises(ValidationError) as ite:
            validator(mock_form, conditions, calculation_total, target_total)

        self.assertEqual(
            error_messages["TOTAL_SUM_NOT_LESS_THAN_OR_EQUALS"] %
            {"total": format_playback_value(target_total)},
            str(ite.exception),
        )