Commit c49ea900 authored by MOREAU Ulysse's avatar MOREAU Ulysse

Update tests

parent 2178330e
......@@ -286,11 +286,15 @@ class Order(models.Model):
super().save(*args, **kwargs)
def clean_illegal_items(self) -> int:
self.refresh_from_db()
# No suppression if already ordered
if self.ordered:
return 0
deleted_count = 0
for orderitem in self.items.all():
print(orderitem, orderitem.item.name)
print(orderitem.pack_parent)
orderitem.refresh_from_db()
if orderitem.pack_parent:
# It is allowed to have an illegal item in a pack
continue
......
......@@ -727,17 +727,30 @@ class OrderTest(PaymentTestCase, OrderItemTestCase):
def test_delete_illegal_items_on_ordered_order(self) -> None:
hidden_item = self.create_item()
ood_item = self.create_item()
pack_with_illegal_children = self.create_item()
pack_with_illegal_children = self.create_pack()
legal_item = self.create_item()
illegal_children = self.create_item()
legal_children = self.create_item()
illegal_child_legal_pack = self.create_item()
legal_child_legal_pack = self.create_item()
illegal_children.hidden = True
illegal_children.save()
illegal_children.refresh_from_db()
illegal_pack_with_children = self.create_pack()
illegal_child_illegal_pack = self.create_item()
legal_child_illegal_pack = self.create_item()
legal_children.save()
legal_children.refresh_from_db()
illegal_pack_with_children.hidden = True
illegal_child_illegal_pack.hidden = True
illegal_pack_with_children.children.add(legal_child_illegal_pack)
illegal_pack_with_children.children.add(illegal_child_illegal_pack)
illegal_pack_with_children.save()
illegal_pack_with_children.refresh_from_db()
illegal_child_legal_pack.hidden = True
illegal_child_legal_pack.save()
illegal_child_legal_pack.refresh_from_db()
legal_child_legal_pack.save()
legal_child_legal_pack.refresh_from_db()
hidden_item.hidden = True
hidden_item.save()
......@@ -753,8 +766,8 @@ class OrderTest(PaymentTestCase, OrderItemTestCase):
legal_item.save()
legal_item.refresh_from_db()
pack_with_illegal_children.children.add(illegal_children)
pack_with_illegal_children.children.add(legal_children)
pack_with_illegal_children.children.add(illegal_child_legal_pack)
pack_with_illegal_children.children.add(legal_child_legal_pack)
pack_with_illegal_children.save()
pack_with_illegal_children.refresh_from_db()
......@@ -762,6 +775,7 @@ class OrderTest(PaymentTestCase, OrderItemTestCase):
ood_item.add_to_order(self.order)
legal_item.add_to_order(self.order)
pack_with_illegal_children.add_to_order(self.order)
illegal_pack_with_children.add_to_order(self.order)
self.order.ordered = True
self.order.save()
......@@ -770,6 +784,7 @@ class OrderTest(PaymentTestCase, OrderItemTestCase):
self.assertTrue(self.order.ordered)
self.assertTrue(hidden_item.contains_illegal_items)
self.assertTrue(ood_item.contains_illegal_items)
self.assertTrue(illegal_pack_with_children.contains_illegal_items)
# You could have illegal items in a legal pack, this should still be valid
# e.g you could hide an item outside of a pack
self.assertFalse(pack_with_illegal_children.contains_illegal_items)
......@@ -789,34 +804,48 @@ class OrderTest(PaymentTestCase, OrderItemTestCase):
def test_delete_illegal_items_on_unordered_order(self) -> None:
hidden_item = self.create_item()
ood_item = self.create_item()
pack_with_illegal_children = self.create_item()
legal_item = self.create_item()
illegal_children = self.create_item()
legal_children = self.create_item()
illegal_children.hidden = True
illegal_children.save()
illegal_children.refresh_from_db()
pack_with_illegal_children = self.create_pack()
illegal_child_legal_pack = self.create_item()
legal_child_legal_pack = self.create_item()
legal_children.save()
legal_children.refresh_from_db()
hidden_item.hidden = True
hidden_item.save()
hidden_item.refresh_from_db()
illegal_pack_with_children = self.create_pack()
illegal_child_illegal_pack = self.create_item()
legal_child_illegal_pack = self.create_item()
# YES, this would have failed anywhere near the year 1970
ood_item.end_date = datetime.datetime(
django_timezone.now().year - 2, 1, 1, 0, 0
)
ood_item.save()
ood_item.refresh_from_db()
hidden_item.hidden = True
illegal_pack_with_children.hidden = True
illegal_child_illegal_pack.hidden = True
illegal_child_legal_pack.hidden = True
hidden_item.save()
ood_item.save()
legal_item.save()
legal_item.refresh_from_db()
illegal_child_legal_pack.save()
legal_child_legal_pack.save()
illegal_child_illegal_pack.save()
legal_child_illegal_pack.save()
pack_with_illegal_children.children.add(illegal_children)
pack_with_illegal_children.children.add(legal_children)
hidden_item.refresh_from_db()
ood_item.refresh_from_db()
legal_item.refresh_from_db()
illegal_child_legal_pack.refresh_from_db()
legal_child_legal_pack.refresh_from_db()
illegal_child_illegal_pack.refresh_from_db()
legal_child_illegal_pack.refresh_from_db()
illegal_pack_with_children.children.add(legal_child_illegal_pack)
illegal_pack_with_children.children.add(illegal_child_illegal_pack)
illegal_pack_with_children.save()
illegal_pack_with_children.refresh_from_db()
pack_with_illegal_children.children.add(illegal_child_legal_pack)
pack_with_illegal_children.children.add(legal_child_legal_pack)
pack_with_illegal_children.save()
pack_with_illegal_children.refresh_from_db()
......@@ -824,12 +853,15 @@ class OrderTest(PaymentTestCase, OrderItemTestCase):
ood_item.add_to_order(self.order)
legal_item.add_to_order(self.order)
pack_with_illegal_children.add_to_order(self.order)
illegal_pack_with_children.add_to_order(self.order)
self.order.save()
self.order.refresh_from_db()
self.assertFalse(self.order.ordered)
self.assertTrue(hidden_item.contains_illegal_items)
self.assertTrue(ood_item.contains_illegal_items)
self.assertTrue(illegal_pack_with_children.contains_illegal_items)
# You could have illegal items in a legal pack, this should still be valid
# e.g you could hide an item outside of a pack
self.assertFalse(pack_with_illegal_children.contains_illegal_items)
......@@ -839,11 +871,12 @@ class OrderTest(PaymentTestCase, OrderItemTestCase):
self.assertTrue(hidden_item in items_in_order)
self.assertTrue(ood_item in items_in_order)
self.assertTrue(illegal_pack_with_children in items_in_order)
self.assertTrue(pack_with_illegal_children in items_in_order)
self.assertTrue(legal_item in items_in_order)
deleted_count = self.order.clean_illegal_items()
self.assertEqual(deleted_count, 2)
self.assertEqual(deleted_count, 3)
self.order.save()
self.order.refresh_from_db()
......@@ -851,5 +884,6 @@ class OrderTest(PaymentTestCase, OrderItemTestCase):
self.assertFalse(hidden_item in items_in_order)
self.assertFalse(ood_item in items_in_order)
self.assertFalse(illegal_pack_with_children in items_in_order)
self.assertTrue(pack_with_illegal_children in items_in_order)
self.assertTrue(legal_item in items_in_order)
Markdown is supported
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