mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add some BomItem tests
- Add a bom fixture
This commit is contained in:
parent
1f80e8c655
commit
c0e3007e4f
29
InvenTree/part/fixtures/bom.yaml
Normal file
29
InvenTree/part/fixtures/bom.yaml
Normal file
@ -0,0 +1,29 @@
|
||||
# Construct a BOM for item 100 'Bob'
|
||||
|
||||
# 10 x M2x4 LPHS
|
||||
- model: part.bomitem
|
||||
fields:
|
||||
part: 100
|
||||
sub_part: 1
|
||||
quantity: 10
|
||||
|
||||
# 40 x R_2K2_0805
|
||||
- model: part.bomitem
|
||||
fields:
|
||||
part: 100
|
||||
sub_part: 3
|
||||
quantity: 40
|
||||
|
||||
# 25 x C_22N_0805
|
||||
- model: part.bomitem
|
||||
fields:
|
||||
part: 100
|
||||
sub_part: 5
|
||||
quantity: 25
|
||||
|
||||
# 3 x Orphan
|
||||
- model: part.bomitem
|
||||
fields:
|
||||
part: 100
|
||||
sub_part: 50
|
||||
quantity: 3
|
@ -5,6 +5,7 @@
|
||||
name: 'M2x4 LPHS'
|
||||
description: 'M2x4 low profile head screw'
|
||||
category: 8
|
||||
|
||||
- model: part.part
|
||||
fields:
|
||||
name: 'M3x12 SHCS'
|
||||
@ -18,6 +19,7 @@
|
||||
name: 'R_2K2_0805'
|
||||
description: '2.2kOhm resistor in 0805 package'
|
||||
category: 2
|
||||
|
||||
- model: part.part
|
||||
fields:
|
||||
name: 'R_4K7_0603'
|
||||
@ -39,7 +41,17 @@
|
||||
category: 7
|
||||
|
||||
- model: part.part
|
||||
pk: 50
|
||||
fields:
|
||||
name: 'Orphan'
|
||||
description: 'A part without a category'
|
||||
category: null
|
||||
category: null
|
||||
|
||||
# A part that can be made from other parts
|
||||
- model: part.part
|
||||
pk: 100
|
||||
fields:
|
||||
name: 'Bob'
|
||||
description: 'Can we build it?'
|
||||
buildable: true
|
||||
|
@ -1,7 +1,37 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from .models import Part
|
||||
|
||||
|
||||
class BomItemTest(TestCase):
|
||||
|
||||
fixtures = [
|
||||
'category',
|
||||
'part',
|
||||
'location',
|
||||
'bom',
|
||||
]
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
self.bob = Part.objects.get(id=100)
|
||||
self.orphan = Part.objects.get(name='Orphan')
|
||||
|
||||
def test_has_bom(self):
|
||||
self.assertFalse(self.orphan.has_bom)
|
||||
self.assertTrue(self.bob.has_bom)
|
||||
|
||||
self.assertEqual(self.bob.bom_count, 4)
|
||||
|
||||
def test_in_bom(self):
|
||||
parts = self.bob.required_parts()
|
||||
|
||||
self.assertIn(self.orphan, parts)
|
||||
|
||||
def test_bom_export(self):
|
||||
parts = self.bob.required_parts()
|
||||
|
||||
data = self.bob.export_bom(format='csv')
|
||||
|
||||
for p in parts:
|
||||
self.assertIn(p.name, data)
|
||||
self.assertIn(p.description, data)
|
||||
|
Loading…
Reference in New Issue
Block a user