Beispiel #1
0
    def test_tansfer_to_account_of_different_currency(self):
        currency = self.create_currency(name="Euro", code="EUR")
        second_account = self.create_prefixed_account(prefix="Second",
                                                      currency=currency)

        data = {
            "from_account": self.account.pk,
            "to_account": second_account.pk,
            "amount": "101.00",
            "rate": "1.98",
        }

        form = InternalTransferForm(user=self.user, data=data)

        self.assertTrue(form.is_valid())

        expected_cleaned_data = {
            "from_account": self.account,
            "to_account": second_account,
            "amount": Decimal("101.00"),
            "rate": Decimal("1.98"),
            "description": "",
        }

        self.assertDictEqual(form.cleaned_data, expected_cleaned_data)
Beispiel #2
0
    def test_tansfer_to_the_same_account(self):
        data = {
            "from_account": self.account.pk,
            "to_account": self.account.pk,
            "amount": "101.00",
        }

        form = InternalTransferForm(user=self.user, data=data)

        self.assertFalse(form.is_valid())

        self.assertEqual(
            form.errors,
            {"__all__": [_("The two accounts shouldn't be the same.")]})
Beispiel #3
0
    def test_tansfer_with_negative_amount(self):
        second_account = self.create_prefixed_account(prefix="Second")

        data = {
            "from_account": self.account.pk,
            "to_account": second_account.pk,
            "amount": "-10",
        }

        form = InternalTransferForm(user=self.user, data=data)

        self.assertFalse(form.is_valid())

        self.assertEqual(
            form.errors,
            {
                "amount":
                [_("Ensure this value is greater than or equal to 0.")]
            },
        )
Beispiel #4
0
    def test_tansfer(self):
        second_account = self.create_prefixed_account(prefix="Second")

        data = {
            "from_account": self.account.pk,
            "to_account": second_account.pk,
            "amount": "101.00",
        }

        form = InternalTransferForm(user=self.user, data=data)

        self.assertTrue(form.is_valid())

        expected_cleaned_data = {
            "from_account": self.account,
            "to_account": second_account,
            "amount": Decimal("101.00"),
            "rate": None,
            "description": "",
        }

        self.assertDictEqual(form.cleaned_data, expected_cleaned_data)
Beispiel #5
0
    def test_tansfer_to_account_of_different_currency_with_rate_missing(self):
        currency = self.create_currency(name="Euro", code="EUR")
        second_account = self.create_prefixed_account(prefix="Second",
                                                      currency=currency)

        data = {
            "from_account": self.account.pk,
            "to_account": second_account.pk,
            "amount": "101.00",
        }

        form = InternalTransferForm(user=self.user, data=data)

        self.assertFalse(form.is_valid())

        self.assertEqual(
            form.errors,
            {
                "__all__": [
                    _("You need to specify exchange rate if the "
                      "two accounts are of different currencies.")
                ]
            },
        )
Beispiel #6
0
    def test_tansfer_to_wrong_account(self):
        user = self.create_user(email="*****@*****.**",
                                password="******")
        wrong_account = self.create_prefixed_account(prefix="Wrong", user=user)

        data = {
            "from_account": self.account.pk,
            "to_account": wrong_account.pk,
            "amount": "101.00",
        }

        form = InternalTransferForm(user=self.user, data=data)

        self.assertFalse(form.is_valid())

        self.assertEqual(
            form.errors,
            {
                "to_account": [
                    _("Select a valid choice. That choice is not one "
                      "of the available choices.")
                ]
            },
        )