|
@@ -1,4 +1,6 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
|
2
|
+import json
|
|
3
|
+
|
2
|
4
|
from django.core.cache import cache
|
3
|
5
|
from django.test import TestCase
|
4
|
6
|
from django.test.utils import override_settings
|
|
@@ -232,6 +234,31 @@ class TestCategoryTemplateTags(TestCase):
|
232
|
234
|
for trail in breadcrumbs:
|
233
|
235
|
create_from_breadcrumbs(trail)
|
234
|
236
|
|
|
237
|
+ def test_category_extra_info(self):
|
|
238
|
+ annotated_list = get_annotated_list(depth=3)
|
|
239
|
+
|
|
240
|
+ expected_categories_info = {
|
|
241
|
+ "Books": {"has_children": True, "len_num_to_close": 0},
|
|
242
|
+ "Fiction": {"has_children": True, "len_num_to_close": 0},
|
|
243
|
+ "Horror": {"has_children": False, "len_num_to_close": 0},
|
|
244
|
+ "Comedy": {"has_children": False, "len_num_to_close": 1},
|
|
245
|
+ "Non-fiction": {"has_children": True, "len_num_to_close": 0},
|
|
246
|
+ "Biography": {"has_children": False, "len_num_to_close": 0},
|
|
247
|
+ "Programming": {"has_children": False, "len_num_to_close": 1},
|
|
248
|
+ "Children": {"has_children": False, "len_num_to_close": 1},
|
|
249
|
+ }
|
|
250
|
+ actual_categories_info = {
|
|
251
|
+ category.name: {
|
|
252
|
+ "has_children": category.get("has_children", False),
|
|
253
|
+ "len_num_to_close": len(category["num_to_close"]),
|
|
254
|
+ }
|
|
255
|
+ for category, _ in annotated_list
|
|
256
|
+ }
|
|
257
|
+ # json.dumps provide an easy way to compare nested dict
|
|
258
|
+ self.assertEqual(
|
|
259
|
+ json.dumps(expected_categories_info), json.dumps(actual_categories_info)
|
|
260
|
+ )
|
|
261
|
+
|
235
|
262
|
def get_category_names(self, depth=None, parent=None):
|
236
|
263
|
"""
|
237
|
264
|
For the tests, we are only interested in the category names returned
|