Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
- Unit test to ensure event is fired when stock item is created OR updated
- Ref: inventree#8546
- Ref: inventree#8452
  • Loading branch information
SchrodingersGat committed Nov 25, 2024
1 parent ee9980e commit 1f465ba
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/backend/InvenTree/stock/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,45 @@ def test_merge(self):
# 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."""
Expand Down

0 comments on commit 1f465ba

Please sign in to comment.