Browse Source

fix: typo in has_children value and tests of annotated list extra info (#4284)

Co-authored-by: Julie Rymer <jrymer@biru.sh>
master
Julie Rymer 10 months ago
parent
commit
5ba48d9840
No account linked to committer's email address

+ 2
- 1
src/oscar/templatetags/category_tags.py View File

@@ -97,6 +97,7 @@ def get_annotated_list(depth=None, parent=None):
97 97
 
98 98
     info = CheapCategoryInfo(parent, url="")
99 99
 
100
+    node_depth = 0
100 101
     for node in categories:
101 102
         node_depth = node.get_depth()
102 103
         if start_depth is None:
@@ -130,6 +131,6 @@ def get_annotated_list(depth=None, parent=None):
130 131
     if prev_depth is not None:
131 132
         # close last leaf
132 133
         info["num_to_close"] = list(range(0, prev_depth - start_depth))
133
-        info["has_children"] = prev_depth > prev_depth
134
+        info["has_children"] = node_depth > prev_depth
134 135
 
135 136
     return annotated_categories

+ 27
- 0
tests/integration/catalogue/test_category.py View File

@@ -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

Loading…
Cancel
Save