mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-06 12:01:41 +00:00
Add unit test for deleting part which has pricing information (#3986)
* Add unit test for deleting part which has pricing information
* Test delete of part without pricing
* Deal with post_delete errors
1. Deleting a Part deleted related objects (e.g. InternalPriceBreak)
2. post_delete signal is called for InternalPriceBreak
3. Subsequent updates to Part / PartPricing throw error
* Add unit test for deleting a Part via the API
- Add InternalPriceBreak so the previous error condition is checked
* Fix for unit test
* More unit test fixes
(cherry picked from commit fa346257f5
)
* Ensure unique part names for unit testing
* Further unit test fixes
This commit is contained in:
@@ -328,3 +328,44 @@ class PartPricingTests(InvenTreeTestCase):
|
||||
|
||||
self.assertEqual(pricing.purchase_cost_min, Money('1.333333', 'USD'))
|
||||
self.assertEqual(pricing.purchase_cost_max, Money('1.764706', 'USD'))
|
||||
|
||||
def test_delete_with_pricing(self):
|
||||
"""Test for deleting a part which has pricing information"""
|
||||
|
||||
# Create some pricing data
|
||||
self.create_price_breaks()
|
||||
|
||||
# Check that pricing does exist
|
||||
pricing = self.part.pricing
|
||||
|
||||
pricing.update_pricing()
|
||||
pricing.save()
|
||||
|
||||
self.assertIsNotNone(pricing.overall_min)
|
||||
self.assertIsNotNone(pricing.overall_max)
|
||||
|
||||
self.part.active = False
|
||||
self.part.save()
|
||||
|
||||
# Remove the part from the database
|
||||
self.part.delete()
|
||||
|
||||
# Check that the pricing was removed also
|
||||
with self.assertRaises(part.models.PartPricing.DoesNotExist):
|
||||
pricing.refresh_from_db()
|
||||
|
||||
def test_delete_without_pricing(self):
|
||||
"""Test that we can delete a part which does not have pricing information"""
|
||||
|
||||
pricing = self.part.pricing
|
||||
|
||||
self.assertIsNone(pricing.pk)
|
||||
|
||||
self.part.active = False
|
||||
self.part.save()
|
||||
|
||||
self.part.delete()
|
||||
|
||||
# Check that part was actually deleted
|
||||
with self.assertRaises(part.models.Part.DoesNotExist):
|
||||
self.part.refresh_from_db()
|
||||
|
Reference in New Issue
Block a user