mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Increase unit testing for BOM item model
This commit is contained in:
parent
3b9f57fc80
commit
c04aa1bff7
@ -43,3 +43,55 @@ class BomItemTest(TestCase):
|
||||
# A validation error should be raised here
|
||||
item = BomItem.objects.create(part=self.bob, sub_part=self.bob, quantity=7)
|
||||
item.clean()
|
||||
|
||||
def test_overage(self):
|
||||
""" Test that BOM line overages are calculated correctly """
|
||||
|
||||
item = BomItem.objects.get(part=100, sub_part=50)
|
||||
|
||||
q = 300
|
||||
|
||||
item.quantity = q
|
||||
|
||||
# Test empty overage
|
||||
n = item.get_overage_quantity(q)
|
||||
self.assertEqual(n, 0)
|
||||
|
||||
# Test improper overage
|
||||
item.overage = 'asf234?'
|
||||
n = item.get_overage_quantity(q)
|
||||
self.assertEqual(n, 0)
|
||||
|
||||
# Test absolute overage
|
||||
item.overage = '3'
|
||||
n = item.get_overage_quantity(q)
|
||||
self.assertEqual(n, 3)
|
||||
|
||||
# Test percentage-based overage
|
||||
item.overage = '5.0 % '
|
||||
n = item.get_overage_quantity(q)
|
||||
self.assertEqual(n, 15)
|
||||
|
||||
# Calculate total required quantity
|
||||
# Quantity = 300 (+ 5%)
|
||||
# Get quantity required to build B = 10
|
||||
# Q * B = 3000 + 5% = 3150
|
||||
n = item.get_required_quantity(10)
|
||||
|
||||
self.assertEqual(n, 3150)
|
||||
|
||||
def test_item_hash(self):
|
||||
""" Test BOM item hash encoding """
|
||||
|
||||
item = BomItem.objects.get(part=100, sub_part=50)
|
||||
|
||||
h1 = item.get_item_hash()
|
||||
|
||||
# Change data - the hash must change
|
||||
item.quantity += 1
|
||||
|
||||
h2 = item.get_item_hash()
|
||||
|
||||
item.validate_hash()
|
||||
|
||||
self.assertNotEqual(h1, h2)
|
||||
|
Loading…
Reference in New Issue
Block a user