mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Unit test for part pricing background task (#4080)
This commit is contained in:
parent
1d411b26a9
commit
6581cb3965
@ -369,3 +369,33 @@ class PartPricingTests(InvenTreeTestCase):
|
||||
# Check that part was actually deleted
|
||||
with self.assertRaises(part.models.Part.DoesNotExist):
|
||||
self.part.refresh_from_db()
|
||||
|
||||
def test_check_missing_pricing(self):
|
||||
"""Tests for check_missing_pricing background task
|
||||
|
||||
Calling the check_missing_pricing task should:
|
||||
- Create PartPricing objects where there are none
|
||||
- Schedule pricing calculations for the newly created PartPricing objects
|
||||
"""
|
||||
|
||||
from part.tasks import check_missing_pricing
|
||||
|
||||
# Create some parts
|
||||
for ii in range(100):
|
||||
part.models.Part.objects.create(
|
||||
name=f"Part_{ii}",
|
||||
description="A test part",
|
||||
)
|
||||
|
||||
# Ensure there is no pricing data
|
||||
part.models.PartPricing.objects.all().delete()
|
||||
|
||||
check_missing_pricing()
|
||||
|
||||
# Check that PartPricing objects have been created
|
||||
self.assertEqual(part.models.PartPricing.objects.count(), 101)
|
||||
|
||||
# Check that background-tasks have been created
|
||||
from django_q.models import OrmQ
|
||||
|
||||
self.assertEqual(OrmQ.objects.count(), 101)
|
||||
|
Loading…
Reference in New Issue
Block a user