mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 20:46:47 +00:00
Add unit test (#8550)
- Unit test to ensure event is fired when stock item is created OR updated - Ref: https://github.com/inventree/InvenTree/pull/8546 - Ref: https://github.com/inventree/InvenTree/issues/8452
This commit is contained in:
parent
51d981a102
commit
d26a683cf1
@ -951,6 +951,45 @@ class StockTest(StockTestBase):
|
||||
# Final purchase price should be the weighted average
|
||||
self.assertAlmostEqual(s1.purchase_price.amount, 16.875, places=3)
|
||||
|
||||
def test_notify_low_stock(self):
|
||||
"""Test that the 'notify_low_stock' task is triggered correctly."""
|
||||
FUNC_NAME = 'part.tasks.notify_low_stock_if_required'
|
||||
|
||||
from django_q.models import OrmQ
|
||||
|
||||
# Start from a blank slate
|
||||
OrmQ.objects.all().delete()
|
||||
|
||||
def check_func() -> bool:
|
||||
"""Check that the 'notify_low_stock_if_required' task has been triggered."""
|
||||
found = False
|
||||
for task in OrmQ.objects.all():
|
||||
if task.func() == FUNC_NAME:
|
||||
found = True
|
||||
break
|
||||
|
||||
# Clear the task queue (for the next test)
|
||||
OrmQ.objects.all().delete()
|
||||
|
||||
return found
|
||||
|
||||
self.assertFalse(check_func())
|
||||
|
||||
part = Part.objects.first()
|
||||
|
||||
# Create a new stock item for this part
|
||||
item = StockItem.objects.create(
|
||||
part=part, quantity=100, location=StockLocation.objects.first()
|
||||
)
|
||||
|
||||
self.assertTrue(check_func())
|
||||
self.assertFalse(check_func())
|
||||
|
||||
# Re-count the stock item
|
||||
item.stocktake(99, None)
|
||||
|
||||
self.assertTrue(check_func())
|
||||
|
||||
|
||||
class StockBarcodeTest(StockTestBase):
|
||||
"""Run barcode tests for the stock app."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user