Changeset View
Changeset View
Standalone View
Standalone View
looper/tests/test_taxes.py
- This file was added.
| from decimal import Decimal | |||||
| from unittest import TestCase | |||||
| from looper.money import Money | |||||
| from looper.taxes import Taxable, TaxType, ProductType | |||||
| class TaxableTest(TestCase): | |||||
| def test_no_charge(self): | |||||
| price = Money('EUR', 10000) | |||||
| taxable = Taxable(price, tax_type=TaxType.NO_CHARGE, tax_rate=Decimal(0)) | |||||
| self.assertEqual(taxable.price_with_tax, price) | |||||
| self.assertEqual(taxable.price, price) | |||||
| self.assertEqual(taxable.tax_type, TaxType.NO_CHARGE) | |||||
| self.assertEqual(taxable.tax_rate, 0) | |||||
| self.assertEqual(taxable.tax, Money('EUR', 0)) | |||||
| self.assertFalse(taxable.tax_is_charged) | |||||
| self.assertEqual(taxable.format_tax_amount(), '') | |||||
| def test_vat_charge(self): | |||||
| price = Money('EUR', 10000) | |||||
| taxable = Taxable(price, tax_type=TaxType.VAT_CHARGE, tax_rate=Decimal(19.0)) | |||||
| self.assertEqual(taxable.price_with_tax, price) | |||||
| self.assertEqual(taxable.price, price) | |||||
| self.assertEqual(taxable.tax_type, TaxType.VAT_CHARGE) | |||||
| self.assertEqual(taxable.tax_rate, 19) | |||||
| self.assertEqual(taxable.tax, Money('EUR', 1900)) | |||||
| self.assertTrue(taxable.tax_is_charged) | |||||
| self.assertEqual(taxable.format_tax_amount(), '(includes VAT 19% €\xa019.00)') | |||||
| def test_vat_reverse_charge(self): | |||||
| price = Money('EUR', 10000) | |||||
| taxable = Taxable(price, tax_type=TaxType.VAT_REVERSE_CHARGE, tax_rate=Decimal(21.0)) | |||||
| self.assertEqual(taxable.price_with_tax, price) | |||||
| self.assertEqual(taxable.price, Money('EUR', 7900)) | |||||
| self.assertEqual(taxable.tax_type, TaxType.VAT_REVERSE_CHARGE) | |||||
| self.assertEqual(taxable.tax_rate, 21) | |||||
| self.assertEqual(taxable.tax, Money('EUR', 2100)) | |||||
| self.assertFalse(taxable.tax_is_charged) | |||||
| self.assertEqual(taxable.format_tax_amount(), '') | |||||
| def test_types_not_equal(self): | |||||
| price = Money('EUR', 10000) | |||||
| self.assertNotEqual( | |||||
| Taxable(price, tax_type=TaxType.VAT_REVERSE_CHARGE, tax_rate=Decimal(21.0)), | |||||
| Taxable(price, tax_type=TaxType.VAT_CHARGE, tax_rate=Decimal(21.0)), | |||||
| ) | |||||
| def test_rates_not_equal(self): | |||||
| price = Money('EUR', 10000) | |||||
| self.assertNotEqual( | |||||
| Taxable(price, tax_type=TaxType.VAT_CHARGE, tax_rate=Decimal(19.0)), | |||||
| Taxable(price, tax_type=TaxType.VAT_CHARGE, tax_rate=Decimal(21.0)), | |||||
| ) | |||||
| def test_price_not_equal(self): | |||||
| price_a = Money('EUR', 10000) | |||||
| price_b = Money('EUR', 9900) | |||||
| self.assertNotEqual( | |||||
| Taxable(price_a, tax_type=TaxType.VAT_CHARGE, tax_rate=Decimal(21.0)), | |||||
| Taxable(price_b, tax_type=TaxType.VAT_CHARGE, tax_rate=Decimal(21.0)), | |||||
| ) | |||||
| def test_equal(self): | |||||
| price = Money('EUR', 9900) | |||||
| self.assertEqual( | |||||
| Taxable(price, tax_type=TaxType.VAT_CHARGE, tax_rate=Decimal(21.0)), | |||||
| Taxable(price, tax_type=TaxType.VAT_CHARGE, tax_rate=Decimal(21.0)), | |||||
| ) | |||||
| class GetVATRateTest(TestCase): | |||||
| def test_unknown_product_type(self): | |||||
| with self.assertRaises(ValueError): | |||||
| ProductType('wut').get_vat_rate('NL') | |||||
| def test_unknown_buyer_country_code(self): | |||||
| self.assertEqual(ProductType('GES').get_vat_rate('WUT'), 0) | |||||
| def test_unknown_buyer_country_code_and_product_type(self): | |||||
| with self.assertRaises(ValueError): | |||||
| ProductType('wut').get_vat_rate('WUT') | |||||
| def test_donation(self): | |||||
| self.assertEqual(ProductType('DNT').get_vat_rate('NL'), 0) | |||||
| def test_generic_electronic_service_nl(self): | |||||
| self.assertEqual(21, ProductType('GES').get_vat_rate('NL')) | |||||
| def test_generic_electronic_service_de(self): | |||||
| self.assertEqual(19, ProductType('GES').get_vat_rate('DE')) | |||||
| class TaxTypeTest(TestCase): | |||||
| def test_get_for_electronic_service_nl_non_business(self): | |||||
| tax_type, tax_rate = ProductType('GES').get_tax('NL', is_business=False) | |||||
| self.assertEqual(tax_type, TaxType.VAT_CHARGE) | |||||
| self.assertEqual(tax_rate, 21) | |||||
| def test_get_for_electronic_service_nl_business(self): | |||||
| tax_type, tax_rate = ProductType('GES').get_tax('NL', is_business=True) | |||||
| self.assertEqual(tax_type, TaxType.VAT_CHARGE) | |||||
| self.assertEqual(tax_rate, 21) | |||||
| def test_get_for_electronic_service_de_non_business(self): | |||||
| tax_type, tax_rate = ProductType('GES').get_tax('DE', is_business=False) | |||||
| self.assertEqual(tax_type, TaxType.VAT_CHARGE) | |||||
| self.assertEqual(tax_rate, 19) | |||||
| def test_get_for_electronic_service_de_business(self): | |||||
| tax_type, tax_rate = ProductType('GES').get_tax('DE', is_business=True) | |||||
| self.assertEqual(tax_type, TaxType.VAT_REVERSE_CHARGE) | |||||
| self.assertEqual(tax_rate, 19) | |||||
| def test_get_for_electronic_service_it_non_business(self): | |||||
| tax_type, tax_rate = ProductType('GES').get_tax('IT', is_business=False) | |||||
| self.assertEqual(tax_type, TaxType.VAT_CHARGE) | |||||
| self.assertEqual(tax_rate, 22) | |||||
| def test_get_for_electronic_service_it_business(self): | |||||
| tax_type, tax_rate = ProductType('GES').get_tax('IT', is_business=True) | |||||
| self.assertEqual(tax_type, TaxType.VAT_REVERSE_CHARGE) | |||||
| self.assertEqual(tax_rate, 22) | |||||
| def test_get_for_electronic_service_us_non_business(self): | |||||
| tax_type, tax_rate = ProductType('GES').get_tax('US', is_business=False) | |||||
| self.assertEqual(tax_type, TaxType.NO_CHARGE) | |||||
| self.assertEqual(tax_rate, 0) | |||||
| def test_get_for_electronic_service_us_business(self): | |||||
| tax_type, tax_rate = ProductType('GES').get_tax('US', is_business=True) | |||||
| self.assertEqual(tax_type, TaxType.NO_CHARGE) | |||||
| self.assertEqual(tax_rate, 0) | |||||