mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add a unit test
This commit is contained in:
parent
1f997d07b6
commit
a9852355c4
@ -1123,6 +1123,59 @@ class BomItemTest(InvenTreeAPITestCase):
|
||||
response = self.get(url, expected_code=200)
|
||||
self.assertEqual(len(response.data), 5)
|
||||
|
||||
def test_bom_item_uses(self):
|
||||
"""
|
||||
Tests for the 'uses' field
|
||||
"""
|
||||
|
||||
url = reverse('api-bom-list')
|
||||
|
||||
# Test that the direct 'sub_part' association works
|
||||
|
||||
assemblies = []
|
||||
|
||||
for i in range(5):
|
||||
assy = Part.objects.create(
|
||||
name=f"Assy_{i}",
|
||||
description="An assembly made of other parts",
|
||||
active=True,
|
||||
assembly=True
|
||||
)
|
||||
|
||||
assemblies.append(assy)
|
||||
|
||||
components = []
|
||||
|
||||
# Create some sub-components
|
||||
for i in range(5):
|
||||
|
||||
cmp = Part.objects.create(
|
||||
name=f"Component_{i}",
|
||||
description="A sub component",
|
||||
active=True,
|
||||
component=True
|
||||
)
|
||||
|
||||
for j in range(i):
|
||||
# Create a BOM item
|
||||
BomItem.objects.create(
|
||||
quantity=10,
|
||||
part=assemblies[j],
|
||||
sub_part=cmp,
|
||||
)
|
||||
|
||||
components.append(cmp)
|
||||
|
||||
response = self.get(
|
||||
url,
|
||||
{
|
||||
'uses': cmp.pk,
|
||||
},
|
||||
expected_code=200,
|
||||
)
|
||||
|
||||
self.assertEqual(len(response.data), i)
|
||||
|
||||
|
||||
class PartParameterTest(InvenTreeAPITestCase):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user