Unit test for part pricing background task (#4080)

This commit is contained in:
Oliver 2022-12-19 13:29:32 +11:00 committed by GitHub
parent 1d411b26a9
commit 6581cb3965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)