def test_application(): tax = LinearTax(1, name='2x Tax') result = tax.apply(Price(Amount(10, 'BTC'), Amount(10, 'BTC'))) assert result.net == Amount(10, 'BTC') assert result.gross == Amount(20, 'BTC') with pytest.raises(TypeError): tax.apply(1)
def test_comparison(): tax1 = LinearTax(1) tax2 = LinearTax(2) assert tax1 == LinearTax(1) assert tax1 != 1 assert tax1 < tax2 assert tax2 > tax1
def test_equality(self): tax1 = LinearTax(1) tax2 = LinearTax(1) tax3 = LinearTax(2) self.assertEqual(tax1, tax2) self.assertNotEqual(tax1, tax3) self.assertNotEqual(tax1, 1)
def test_pricerange(): tax_name = '2x Tax' tax = LinearTax(1, name=tax_name) price_range = PriceRange( Price(Amount(10, 'BTC'), Amount(10, 'BTC')), Price(Amount(20, 'BTC'), Amount(20, 'BTC'))) result = tax.apply(price_range) assert result.min_price == Price(Amount(10, 'BTC'), Amount(20, 'BTC')) assert result.max_price == Price(Amount(20, 'BTC'), Amount(40, 'BTC'))
def test_pricerange(self): tax_name = '2x Tax' tax = LinearTax(1, name=tax_name) pr = self.range_ten_twenty | tax self.assertEqual(pr.min_price.net, self.ten_btc.net) self.assertEqual(pr.min_price.gross, self.ten_btc.gross * 2) self.assertEqual(pr.min_price.currency, self.ten_btc.currency) self.assertEqual(pr.max_price.net, self.twenty_btc.net) self.assertEqual(pr.max_price.gross, self.twenty_btc.gross * 2) self.assertEqual(pr.max_price.currency, self.twenty_btc.currency)
for json_dict in [json_success, json_success_without_reduced_rates]: utils.create_objects_from_json(json_dict) assert VAT.objects.count() == 2 @pytest.mark.django_db def test_save_vat_rate_types(json_types_success): utils.save_vat_rate_types(json_types_success) assert 1 == RateTypes.objects.count() utils.save_vat_rate_types(json_types_success) assert 1 == RateTypes.objects.count() @pytest.mark.parametrize('rate_name,expected', [('medicine', LinearTax(20 / 100, 'AT - medicine')), ('standard', LinearTax(20 / 100, 'AT - standard')), ('books', LinearTax(10 / 100, 'AT - books')), (None, LinearTax(20 / 100, 'AT - None'))]) def test_get_tax_for_country(vat_country, rate_name, expected): country_code = vat_country.country_code rate = utils.get_tax_for_country(country_code, rate_name) assert rate == expected @pytest.mark.parametrize('rate_name,expected', [('medicine', LinearTax(20 / 100, 'AZ - medicine')), ('standard', LinearTax(20 / 100, 'AZ - standard')), (None, LinearTax(20 / 100, 'AZ - None'))]) def test_get_tax_for_country(vat_without_reduced_rates, rate_name, expected): country_code = vat_without_reduced_rates.country_code
def test_repr(): tax = LinearTax(decimal.Decimal('1.23'), name='VAT') assert repr(tax) == "LinearTax('1.23', name='VAT')"
def get_tax(self): return LinearTax(self.rate * decimal.Decimal('0.01'), self.rate_name)
def test_repr(self): tax = LinearTax(decimal.Decimal('1.23'), name='VAT') self.assertEqual(repr(tax), "LinearTax('1.23', name='VAT')")
def test_comparison(self): tax1 = LinearTax(1) tax2 = LinearTax(2) self.assertTrue(tax1 < tax2) self.assertTrue(tax2 > tax1)
def test_price(self): tax = LinearTax(1, name='2x Tax') p = self.ten_btc | tax self.assertEqual(p.net, self.ten_btc.net) self.assertEqual(p.gross, self.ten_btc.gross * 2) self.assertEqual(p.currency, self.ten_btc.currency)
def test_comparison(self): tax1 = LinearTax(1) tax2 = LinearTax(2) self.assertTrue(tax1 < tax2) self.assertTrue(tax2 > tax1) self.assertRaises(TypeError, lambda: tax1 < 10)
def get_price(self, discount=True, **kwargs): price = Price('5', currency='PLN') if discount: price *= decimal.Decimal('0.9') price += LinearTax('0.9', 'Tax!') return price