mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-29 20:30:39 +00:00 
			
		
		
		
	Increase unit testing for BOM item model
This commit is contained in:
		| @@ -43,3 +43,55 @@ class BomItemTest(TestCase): | |||||||
|             # A validation error should be raised here |             # A validation error should be raised here | ||||||
|             item = BomItem.objects.create(part=self.bob, sub_part=self.bob, quantity=7) |             item = BomItem.objects.create(part=self.bob, sub_part=self.bob, quantity=7) | ||||||
|             item.clean() |             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) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user