Skip to content

Commit

Permalink
fix: typo in has_children value and tests of annotated list extra info
Browse files Browse the repository at this point in the history
  • Loading branch information
Julie Rymer committed Apr 23, 2024
1 parent 992e1c6 commit fda6d46
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/oscar/templatetags/category_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def get_annotated_list(depth=None, parent=None):

info = CheapCategoryInfo(parent, url="")

node_depth = 0
for node in categories:
node_depth = node.get_depth()
if start_depth is None:
Expand Down Expand Up @@ -130,6 +131,6 @@ def get_annotated_list(depth=None, parent=None):
if prev_depth is not None:
# close last leaf
info["num_to_close"] = list(range(0, prev_depth - start_depth))
info["has_children"] = prev_depth > prev_depth
info["has_children"] = node_depth > prev_depth

return annotated_categories
27 changes: 27 additions & 0 deletions tests/integration/catalogue/test_category.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import json

from django.core.cache import cache
from django.test import TestCase
from django.test.utils import override_settings
Expand Down Expand Up @@ -232,6 +234,31 @@ def setUp(self):
for trail in breadcrumbs:
create_from_breadcrumbs(trail)

def test_category_extra_info(self):
annotated_list = get_annotated_list(depth=3)

expected_categories_info = {
"Books": {"has_children": True, "len_num_to_close": 0},
"Fiction": {"has_children": True, "len_num_to_close": 0},
"Horror": {"has_children": False, "len_num_to_close": 0},
"Comedy": {"has_children": False, "len_num_to_close": 1},
"Non-fiction": {"has_children": True, "len_num_to_close": 0},
"Biography": {"has_children": False, "len_num_to_close": 0},
"Programming": {"has_children": False, "len_num_to_close": 1},
"Children": {"has_children": False, "len_num_to_close": 1},
}
actual_categories_info = {
category.name: {
"has_children": category.get("has_children", False),
"len_num_to_close": len(category["num_to_close"]),
}
for category, _ in annotated_list
}
# json.dumps provide an easy way to compare nested dict
self.assertEqual(
json.dumps(expected_categories_info), json.dumps(actual_categories_info)
)

def get_category_names(self, depth=None, parent=None):
"""
For the tests, we are only interested in the category names returned
Expand Down

0 comments on commit fda6d46

Please sign in to comment.