mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Added some more BomItem tests
This commit is contained in:
parent
c0e3007e4f
commit
e2ced18753
@ -477,8 +477,8 @@ class BomItem(models.Model):
|
||||
unique_together = ('part', 'sub_part')
|
||||
|
||||
def __str__(self):
|
||||
return "{par} -> {child} ({n})".format(
|
||||
par=self.part.name,
|
||||
return "{n} x {child} to make {parent}".format(
|
||||
parent=self.part.name,
|
||||
child=self.sub_part.name,
|
||||
n=self.quantity)
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django.test import TestCase
|
||||
import django.core.exceptions as django_exceptions
|
||||
|
||||
from .models import Part
|
||||
from .models import Part, BomItem
|
||||
|
||||
|
||||
class BomItemTest(TestCase):
|
||||
@ -16,6 +17,10 @@ class BomItemTest(TestCase):
|
||||
self.bob = Part.objects.get(id=100)
|
||||
self.orphan = Part.objects.get(name='Orphan')
|
||||
|
||||
def test_str(self):
|
||||
b = BomItem.objects.get(id=1)
|
||||
self.assertEqual(str(b), '10 x M2x4 LPHS to make Bob')
|
||||
|
||||
def test_has_bom(self):
|
||||
self.assertFalse(self.orphan.has_bom)
|
||||
self.assertTrue(self.bob.has_bom)
|
||||
@ -35,3 +40,15 @@ class BomItemTest(TestCase):
|
||||
for p in parts:
|
||||
self.assertIn(p.name, data)
|
||||
self.assertIn(p.description, data)
|
||||
|
||||
def test_used_in(self):
|
||||
self.assertEqual(self.bob.used_in_count, 0)
|
||||
self.assertEqual(self.orphan.used_in_count, 1)
|
||||
|
||||
def test_self_reference(self):
|
||||
""" Test that we get an appropriate error when we create a BomItem which points to itself """
|
||||
|
||||
with self.assertRaises(django_exceptions.ValidationError):
|
||||
# A validation error should be raised here
|
||||
item = BomItem.objects.create(part=self.bob, sub_part=self.bob, quantity=7)
|
||||
item.clean()
|
||||
|
Loading…
Reference in New Issue
Block a user