瀏覽代碼

Return True in is_tax_known() when the basket is empty (#4166)

* Fix AbstractBasket's is_tax_known() to handle an empty basket

* Fix lint errors

* Added another test for is_tax_known

* Improved clarity of complex expression
master
TopDevPros 2 年之前
父節點
當前提交
39e7c8d7d9
沒有連結到貢獻者的電子郵件帳戶。

+ 6
- 2
src/oscar/apps/basket/abstract_models.py 查看文件

465
     @property
465
     @property
466
     def is_tax_known(self):
466
     def is_tax_known(self):
467
         """
467
         """
468
-        Test if tax values are known for this basket
468
+        Test if tax values are known for this basket.
469
+
470
+        If the basket is empty, then tax values are unknown.
469
         """
471
         """
470
-        return all([line.is_tax_known for line in self.all_lines()])
472
+        return (not self.is_empty) and all(
473
+            [line.is_tax_known for line in self.all_lines()]
474
+        )
471
 
475
 
472
     @property
476
     @property
473
     def total_excl_tax(self):
477
     def total_excl_tax(self):

+ 7
- 0
tests/integration/basket/test_models.py 查看文件

41
     def test_has_no_applied_offers(self):
41
     def test_has_no_applied_offers(self):
42
         self.assertEqual({}, self.basket.applied_offers())
42
         self.assertEqual({}, self.basket.applied_offers())
43
 
43
 
44
+    def test_is_tax_unknown(self):
45
+        self.assertTrue(self.basket.is_empty)
46
+        self.assertFalse(self.basket.is_tax_known)
47
+
44
 
48
 
45
 class TestBasketLine(TestCase):
49
 class TestBasketLine(TestCase):
46
     def test_description(self):
50
     def test_description(self):
143
         with self.assertRaises(ValueError):
147
         with self.assertRaises(ValueError):
144
             self.basket.add(product)
148
             self.basket.add(product)
145
 
149
 
150
+    def test_is_tax_known(self):
151
+        self.assertTrue(self.basket.is_tax_known)
152
+
146
 
153
 
147
 class TestANonEmptyBasket(TestCase):
154
 class TestANonEmptyBasket(TestCase):
148
     def setUp(self):
155
     def setUp(self):

+ 3
- 2
tests/integration/order/test_creator.py 查看文件

206
     def setUp(self):
206
     def setUp(self):
207
         self.creator = OrderCreator()
207
         self.creator = OrderCreator()
208
         self.basket = factories.create_basket(empty=True)
208
         self.basket = factories.create_basket(empty=True)
209
+
210
+        # add the product now so we can calculate the correct surcharges
211
+        add_product(self.basket, D("12.00"))
209
         self.surcharges = SurchargeApplicator().get_applicable_surcharges(self.basket)
212
         self.surcharges = SurchargeApplicator().get_applicable_surcharges(self.basket)
210
 
213
 
211
     def apply_20percent_shipping_offer(self):
214
     def apply_20percent_shipping_offer(self):
221
         return offer
224
         return offer
222
 
225
 
223
     def test_shipping_offer_is_applied(self):
226
     def test_shipping_offer_is_applied(self):
224
-        add_product(self.basket, D("12.00"))
225
         offer = self.apply_20percent_shipping_offer()
227
         offer = self.apply_20percent_shipping_offer()
226
 
228
 
227
         shipping = FixedPrice(D("5.00"), D("5.00"))
229
         shipping = FixedPrice(D("5.00"), D("5.00"))
241
         self.assertEqual(D("38.00"), order.total_incl_tax)
243
         self.assertEqual(D("38.00"), order.total_incl_tax)
242
 
244
 
243
     def test_zero_shipping_discount_is_not_created(self):
245
     def test_zero_shipping_discount_is_not_created(self):
244
-        add_product(self.basket, D("12.00"))
245
         offer = self.apply_20percent_shipping_offer()
246
         offer = self.apply_20percent_shipping_offer()
246
 
247
 
247
         shipping = Free()
248
         shipping = Free()

Loading…
取消
儲存