2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 12:06:44 +00:00

Fixed test cases

This commit is contained in:
Oliver Walters 2019-06-18 01:38:43 +10:00
parent ea0da4c8f8
commit a47be24410
3 changed files with 8 additions and 11 deletions

View File

@ -80,7 +80,7 @@ class InvenTreeTree(models.Model):
return unique return unique
def getUniqueChildren(self, unique=None, include_self=False): def getUniqueChildren(self, unique=None, include_self=True):
""" Return a flat set of all child items that exist under this node. """ Return a flat set of all child items that exist under this node.
If any child items are repeated, the repetitions are omitted. If any child items are repeated, the repetitions are omitted.
""" """
@ -88,13 +88,11 @@ class InvenTreeTree(models.Model):
if unique is None: if unique is None:
unique = set() unique = set()
if include_self:
unique.add(self.id)
if self.id in unique: if self.id in unique:
return unique return unique
unique.add(self.id) if include_self:
unique.add(self.id)
# Some magic to get around the limitations of abstract models # Some magic to get around the limitations of abstract models
contents = ContentType.objects.get_for_model(type(self)) contents = ContentType.objects.get_for_model(type(self))
@ -185,7 +183,7 @@ class InvenTreeTree(models.Model):
pass pass
# Ensure that the new parent is not already a child # Ensure that the new parent is not already a child
if self.id in self.getUniqueChildren(): if self.id in self.getUniqueChildren(include_self=False):
raise ValidationError("Category cannot set a child as parent") raise ValidationError("Category cannot set a child as parent")
def __str__(self): def __str__(self):

View File

@ -167,8 +167,7 @@ class PartList(generics.ListCreateAPIView):
if cat_id: if cat_id:
try: try:
category = PartCategory.objects.get(pk=cat_id) category = PartCategory.objects.get(pk=cat_id)
cats = category.getUniqueChildren(include_self=True) parts_list = parts_list.filter(category__in=category.getUniqueChildren())
parts_list = parts_list.filter(category__in=cats)
except PartCategory.DoesNotExist: except PartCategory.DoesNotExist:
pass pass

View File

@ -82,10 +82,10 @@ class CategoryTest(TestCase):
self.assertTrue(self.fasteners.has_parts) self.assertTrue(self.fasteners.has_parts)
self.assertFalse(self.transceivers.has_parts) self.assertFalse(self.transceivers.has_parts)
self.assertEqual(self.fasteners.partcount, 2) self.assertEqual(self.fasteners.partcount(), 2)
self.assertEqual(self.capacitors.partcount, 1) self.assertEqual(self.capacitors.partcount(), 1)
self.assertEqual(self.electronics.partcount, 3) self.assertEqual(self.electronics.partcount(), 3)
def test_delete(self): def test_delete(self):
""" Test that category deletion moves the children properly """ """ Test that category deletion moves the children properly """