Unit testing for part variant MPTT

This commit is contained in:
Oliver Walters 2020-05-15 22:01:21 +10:00
parent 0652579312
commit 2d6c531fda
2 changed files with 70 additions and 1 deletions

View File

@ -97,4 +97,61 @@
tree_id: 0
level: 0
lft: 0
rght: 0
rght: 0
# A 'template' part
- model: part.part
pk: 10000
fields:
name: 'Chair Template'
description: 'A chair'
is_template: True
category: 7
tree_id: 1
level: 0
lft: 0
rght: 0
- model: part.part
pk: 10001
fields:
name: 'Blue Chair'
variant_of: 10000
category: 7
tree_id: 1
level: 0
lft: 0
rght: 0
- model: part.part
pk: 10002
fields:
name: 'Red chair'
variant_of: 10000
category: 7
tree_id: 1
level: 0
lft: 0
rght: 0
- model: part.part
pk: 10003
fields:
name: 'Green chair'
variant_of: 10000
category: 7
tree_id: 1
level: 0
lft: 0
rght: 0
- model: part.part
pk: 10004
fields:
name: 'Green chair variant'
variant_of: 10003
category:
tree_id: 1
level: 0
lft: 0
rght: 0

View File

@ -52,6 +52,18 @@ class PartTest(TestCase):
self.C1 = Part.objects.get(name='C_22N_0805')
Part.objects.rebuild()
def test_tree(self):
# Test that the part variant tree is working properly
chair = Part.objects.get(pk=10000)
self.assertEqual(chair.get_children().count(), 3)
self.assertEqual(chair.get_descendant_count(), 4)
green = Part.objects.get(pk=10004)
self.assertEqual(green.get_ancestors().count(), 2)
self.assertEqual(green.get_root(), chair)
def test_str(self):
p = Part.objects.get(pk=100)
self.assertEqual(str(p), "BOB | Bob | A2 - Can we build it?")