Commit 47b235a4 authored by VAN ZUIJLEN Nils's avatar VAN ZUIJLEN Nils
Browse files

Add tests and optimization to Order.contains_cotiz

`any` takes an iterable, no need to create a list if it's only to
use it once!
parent 9ef7a721
......@@ -244,7 +244,7 @@ class Order(models.Model):
@property
def contains_cotiz(self) -> bool:
return any([i.item.is_cotiz for i in self.items.all()])
return any(i.item.is_cotiz for i in self.items.all())
def compute_price(self) -> None:
self.price = Decimal("0.00")
......
......@@ -646,6 +646,42 @@ class OrderTest(PaymentTestCase, OrderItemTestCase):
self.assertTrue(self.order.paid)
def test_contains_cotiz_single_items(self) -> None:
"""Tests that Order.contains_cotiz is able to detect single cotiz"""
item = self.create_item()
cotiz = self.create_item()
cotiz.action = "full_cotiz"
cotiz.save()
cotiz.refresh_from_db()
self.assertFalse(self.order.contains_cotiz)
item.add_to_order(self.order)
self.assertFalse(self.order.contains_cotiz)
cotiz.add_to_order(self.order)
self.assertTrue(self.order.contains_cotiz)
def test_contains_cotiz_packs(self) -> None:
"""Tests that Order.contains_cotiz is able to detect cotiz in packs"""
pack = self.create_pack()
cpack = self.create_item()
cotiz = self.create_item()
cotiz.action = "full_cotiz"
cotiz.save()
cotiz.refresh_from_db()
cpack.children.add(cotiz)
cpack.save()
cpack.refresh_from_db()
self.assertFalse(self.order.contains_cotiz)
pack.add_to_order(self.order)
self.assertFalse(self.order.contains_cotiz)
cpack.add_to_order(self.order)
self.assertTrue(self.order.contains_cotiz)
@patch("boutique.models.OrderItem.post_payment")
def test_post_payment(self, oi_post_payment) -> None:
item = self.create_item()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment