From a47be24410543b8fef493f1ca65daa424d4ed3b2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 18 Jun 2019 01:38:43 +1000 Subject: [PATCH] Fixed test cases --- InvenTree/InvenTree/models.py | 10 ++++------ InvenTree/part/api.py | 3 +-- InvenTree/part/test_category.py | 6 +++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index f3bc9a43cd..646515ce70 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -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): diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index 64956a60de..22f371c379 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -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 diff --git a/InvenTree/part/test_category.py b/InvenTree/part/test_category.py index ea52396342..3b3fe36b08 100644 --- a/InvenTree/part/test_category.py +++ b/InvenTree/part/test_category.py @@ -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 """