Unit test fixes

This commit is contained in:
Oliver 2021-09-07 17:36:53 +10:00
parent 918106c225
commit 5ab4be7025
3 changed files with 15 additions and 4 deletions

View File

@ -1305,7 +1305,6 @@ class StockItem(MPTTModel):
self.quantity = quantity
if quantity == 0 and self.delete_on_deplete and self.can_delete():
self.mark_for_deletion()

View File

@ -30,6 +30,6 @@ def delete_old_stock_items():
items = StockItem.objects.filter(scheduled_for_deletion=True)
logger.info(f"Removing {items.count()} StockItem objects scheduled for deletion")
items.delete()
if items.count() > 0:
logger.info(f"Removing {items.count()} StockItem objects scheduled for deletion")
items.delete()

View File

@ -332,6 +332,8 @@ class StockTest(TestCase):
w1 = StockItem.objects.get(pk=100)
w2 = StockItem.objects.get(pk=101)
self.assertFalse(w2.scheduled_for_depletion)
# Take 25 units from w1 (there are only 10 in stock)
w1.take_stock(30, None, notes='Took 30')
@ -342,6 +344,16 @@ class StockTest(TestCase):
# Take 25 units from w2 (will be deleted)
w2.take_stock(30, None, notes='Took 30')
# w2 should now be marked for future deletion
w2 = StockItem.objects.get(pk=101)
self.assertTrue(w2.scheduled_for_depletion)
from stock.tasks import delete_old_stock_items
# Now run the "background task" to delete these stock items
delete_old_stock_items()
# This StockItem should now have been deleted
with self.assertRaises(StockItem.DoesNotExist):
w2 = StockItem.objects.get(pk=101)