From 43c3a2f12ba0947882ffbac1ab4ea9a3c46cf64a Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Mon, 26 Dec 2016 03:06:00 +0100
Subject: [PATCH] testCMFCategory: Simplify and extend.

Instead of only testing the number of related documents and expecting them
to match without checking, do check what the found documents are.
In turn, drop now-redundant comments.
Also, check Category-in-Category case.
---
 product/CMFCategory/tests/testCMFCategory.py | 22 +++++++++-----------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/product/CMFCategory/tests/testCMFCategory.py b/product/CMFCategory/tests/testCMFCategory.py
index f37c61d14a..9c24ca2922 100644
--- a/product/CMFCategory/tests/testCMFCategory.py
+++ b/product/CMFCategory/tests/testCMFCategory.py
@@ -608,21 +608,19 @@ class TestCMFCategory(ERP5TypeTestCase):
     """ Checks on getting related values"""
     pc = self.getCategoriesTool()
     bc = pc.newContent(portal_type='Base Category', id='related_value_test')
-    self.assertTrue(bc is not None)
     self.tic()
-    # A newly created base category should be referred to only by itself
-    value_list = pc.getRelatedValueList(bc)
-    self.assertEqual(len(value_list), 1)
+    self.assertItemsEqual(pc.getRelatedValueList(bc), [bc])
+
+    c1 = bc.newContent(portal_type='Category', id='1')
+    self.tic()
+    self.assertItemsEqual(pc.getRelatedValueList(bc), [bc, c1])
+    self.assertItemsEqual(pc.getRelatedValueList(c1), [c1])
 
-    c = bc.newContent(portal_type='Category', id='1')
-    self.assertTrue(c is not None)
+    c11 = c1.newContent(portal_type='Category', id='1')
     self.tic()
-    value_list = pc.getRelatedValueList(bc)
-    # Now the base category should be referred to by itself and this sub category
-    self.assertEqual(len(value_list), 2)
-    # This sub category should be referred to only by itself
-    value_list = pc.getRelatedValueList(c)
-    self.assertEqual(len(value_list), 1)
+    self.assertItemsEqual(pc.getRelatedValueList(bc), [bc, c1, c11])
+    self.assertItemsEqual(pc.getRelatedValueList(c1), [c1, c11])
+    self.assertItemsEqual(pc.getRelatedValueList(c11), [c11])
 
     #test _getDefaultRelatedProperty Accessor
     person = self.portal.person_module.newContent(id='person_test')
-- 
GitLab