forked from dj-stripe/dj-stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_tax_rates.py
65 lines (52 loc) · 1.93 KB
/
test_tax_rates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"""
dj-stripe TaxRate Model Tests.
"""
from copy import deepcopy
from decimal import Decimal
import pytest
from django.test import TestCase
from djstripe.models import TaxRate
from tests import FAKE_TAX_RATE_EXAMPLE_1_VAT
pytestmark = pytest.mark.django_db
from .conftest import CreateAccountMixin
class TaxRateTest(CreateAccountMixin, TestCase):
def test_sync_from_stripe_data(self):
tax_rate = TaxRate.sync_from_stripe_data(deepcopy(FAKE_TAX_RATE_EXAMPLE_1_VAT))
self.assertEqual(
FAKE_TAX_RATE_EXAMPLE_1_VAT["id"],
tax_rate.id,
)
def test___str__(self):
tax_rate = TaxRate.sync_from_stripe_data(deepcopy(FAKE_TAX_RATE_EXAMPLE_1_VAT))
self.assertEqual(
(
f"{FAKE_TAX_RATE_EXAMPLE_1_VAT['display_name']} at"
f" {FAKE_TAX_RATE_EXAMPLE_1_VAT['percentage']:.4f}%"
),
str(tax_rate),
)
class TestTaxRateDecimal(CreateAccountMixin):
@pytest.mark.parametrize(
"inputted,expected",
[
(Decimal("1"), Decimal("1.0000")),
(Decimal("1.5234567"), Decimal("1.5235")),
(Decimal("0"), Decimal("0.0000")),
(Decimal("23.2345678"), Decimal("23.2346")),
("1", Decimal("1.0000")),
("1.5234567", Decimal("1.5235")),
("0", Decimal("0.0000")),
("23.2345678", Decimal("23.2346")),
(1, Decimal("1.0000")),
(1.5234567, Decimal("1.5235")),
(0, Decimal("0.0000")),
(23.2345678, Decimal("23.2346")),
],
)
def test_decimal_tax_percent(self, inputted, expected):
fake_tax_rate = deepcopy(FAKE_TAX_RATE_EXAMPLE_1_VAT)
fake_tax_rate["percentage"] = inputted
tax_rate = TaxRate.sync_from_stripe_data(fake_tax_rate)
field_data = tax_rate.percentage
assert isinstance(field_data, Decimal)
assert field_data == expected