mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
Fixed test cases
This commit is contained in:
parent
ea0da4c8f8
commit
a47be24410
@ -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,12 +88,10 @@ 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
|
||||||
|
|
||||||
|
if include_self:
|
||||||
unique.add(self.id)
|
unique.add(self.id)
|
||||||
|
|
||||||
# Some magic to get around the limitations of abstract models
|
# Some magic to get around the limitations of abstract models
|
||||||
@ -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):
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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 """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user