mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fixed test cases
This commit is contained in:
parent
ea0da4c8f8
commit
a47be24410
@ -80,7 +80,7 @@ class InvenTreeTree(models.Model):
|
||||
|
||||
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.
|
||||
If any child items are repeated, the repetitions are omitted.
|
||||
"""
|
||||
@ -88,13 +88,11 @@ class InvenTreeTree(models.Model):
|
||||
if unique is None:
|
||||
unique = set()
|
||||
|
||||
if include_self:
|
||||
unique.add(self.id)
|
||||
|
||||
if self.id in unique:
|
||||
return unique
|
||||
|
||||
unique.add(self.id)
|
||||
if include_self:
|
||||
unique.add(self.id)
|
||||
|
||||
# Some magic to get around the limitations of abstract models
|
||||
contents = ContentType.objects.get_for_model(type(self))
|
||||
@ -185,7 +183,7 @@ class InvenTreeTree(models.Model):
|
||||
pass
|
||||
|
||||
# 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")
|
||||
|
||||
def __str__(self):
|
||||
|
@ -167,8 +167,7 @@ class PartList(generics.ListCreateAPIView):
|
||||
if cat_id:
|
||||
try:
|
||||
category = PartCategory.objects.get(pk=cat_id)
|
||||
cats = category.getUniqueChildren(include_self=True)
|
||||
parts_list = parts_list.filter(category__in=cats)
|
||||
parts_list = parts_list.filter(category__in=category.getUniqueChildren())
|
||||
except PartCategory.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
@ -82,10 +82,10 @@ class CategoryTest(TestCase):
|
||||
self.assertTrue(self.fasteners.has_parts)
|
||||
self.assertFalse(self.transceivers.has_parts)
|
||||
|
||||
self.assertEqual(self.fasteners.partcount, 2)
|
||||
self.assertEqual(self.capacitors.partcount, 1)
|
||||
self.assertEqual(self.fasteners.partcount(), 2)
|
||||
self.assertEqual(self.capacitors.partcount(), 1)
|
||||
|
||||
self.assertEqual(self.electronics.partcount, 3)
|
||||
self.assertEqual(self.electronics.partcount(), 3)
|
||||
|
||||
def test_delete(self):
|
||||
""" Test that category deletion moves the children properly """
|
||||
|
Loading…
Reference in New Issue
Block a user