-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Cut children from inactive menu nodes when level is less or equal to 0 (#8322) #8324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
#8322) It can be less than zero when the from_level is greater than zero. Co-authored-by: Fabian Braun <[email protected]>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR refines the menu pruning logic to clear children when levels is non-positive and adds a corresponding test to verify inactive node removal at or below zero levels. Class diagram for updated cut_after function in menu_tagsclassDiagram
class Node {
children: list[Node]
}
class menu_tags {
+cut_after(node: Node, levels: int)
}
Node <|-- menu_tags
menu_tags : cut_after(node, levels)
menu_tags : if levels <= 0 then node.children = []
menu_tags : else recursively cut_after(child, levels-1)
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
π Hi there! Please remember to MERGE COMMIT pull requests from Do not SQUASH commits to preserve history for the changelog. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- Consider adding a test case for negative levels to explicitly verify that any levels < 0 also result in children being cut.
- Update the cut_after docstring to mention that non-positive levels (<=0) will clear all children, so the behavior is clear in the API docs.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding a test case for negative levels to explicitly verify that any levels < 0 also result in children being cut.
- Update the cut_after docstring to mention that non-positive levels (<=0) will clear all children, so the behavior is clear in the API docs.
## Individual Comments
### Comment 1
<location> `cms/tests/test_menu.py:230` </location>
<code_context>
tpl = Template("{% load menu_tags %}{% show_menu 0 0 0 0 'menu/menu.html' child %}")
self.assertRaises(TemplateSyntaxError, tpl.render, context)
+ def test_show_menu_cut_inactive(self):
+ root = self.get_page(2)
+ context = self.get_context(page=root)
+ tpl = Template("{% load menu_tags %}{% show_menu 1 100 0 1 %}")
+ tpl.render(context)
+ nodes = context["children"]
+ self.assertEqual(len(nodes), 2)
+ self.assertEqual(len(nodes[0].children), 1)
+ self.assertEqual(len(nodes[1].children), 0)
+
def test_show_submenu_nephews(self):
</code_context>
<issue_to_address>
Consider adding tests for negative level values and edge cases.
Please add a test for negative level values (e.g., -1) to verify that children are correctly handled. Also, consider testing with levels > 0 and no children to ensure the logic is robust.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
def test_show_menu_cut_inactive(self):
root = self.get_page(2)
context = self.get_context(page=root)
tpl = Template("{% load menu_tags %}{% show_menu 1 100 0 1 %}")
tpl.render(context)
nodes = context["children"]
self.assertEqual(len(nodes), 2)
self.assertEqual(len(nodes[0].children), 1)
self.assertEqual(len(nodes[1].children), 0)
=======
def test_show_menu_cut_inactive(self):
root = self.get_page(2)
context = self.get_context(page=root)
tpl = Template("{% load menu_tags %}{% show_menu 1 100 0 1 %}")
tpl.render(context)
nodes = context["children"]
self.assertEqual(len(nodes), 2)
self.assertEqual(len(nodes[0].children), 1)
self.assertEqual(len(nodes[1].children), 0)
def test_show_menu_negative_level(self):
root = self.get_page(2)
context = self.get_context(page=root)
tpl = Template("{% load menu_tags %}{% show_menu -1 100 0 0 %}")
tpl.render(context)
nodes = context["children"]
# Expecting no children for negative level, or specific behavior depending on implementation
self.assertIsInstance(nodes, list)
self.assertEqual(len(nodes), 0)
def test_show_menu_positive_level_no_children(self):
# Create a page with no children
root = self.get_page(3)
context = self.get_context(page=root)
tpl = Template("{% load menu_tags %}{% show_menu 2 100 0 0 %}")
tpl.render(context)
nodes = context["children"]
self.assertIsInstance(nodes, list)
self.assertEqual(len(nodes), 0)
>>>>>>> REPLACE
</suggested_fix>
Help me be more useful! Please click π or π on each comment and I'll use the feedback to improve your reviews.
def test_show_menu_cut_inactive(self): | ||
root = self.get_page(2) | ||
context = self.get_context(page=root) | ||
tpl = Template("{% load menu_tags %}{% show_menu 1 100 0 1 %}") | ||
tpl.render(context) | ||
nodes = context["children"] | ||
self.assertEqual(len(nodes), 2) | ||
self.assertEqual(len(nodes[0].children), 1) | ||
self.assertEqual(len(nodes[1].children), 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Consider adding tests for negative level values and edge cases.
Please add a test for negative level values (e.g., -1) to verify that children are correctly handled. Also, consider testing with levels > 0 and no children to ensure the logic is robust.
def test_show_menu_cut_inactive(self): | |
root = self.get_page(2) | |
context = self.get_context(page=root) | |
tpl = Template("{% load menu_tags %}{% show_menu 1 100 0 1 %}") | |
tpl.render(context) | |
nodes = context["children"] | |
self.assertEqual(len(nodes), 2) | |
self.assertEqual(len(nodes[0].children), 1) | |
self.assertEqual(len(nodes[1].children), 0) | |
def test_show_menu_cut_inactive(self): | |
root = self.get_page(2) | |
context = self.get_context(page=root) | |
tpl = Template("{% load menu_tags %}{% show_menu 1 100 0 1 %}") | |
tpl.render(context) | |
nodes = context["children"] | |
self.assertEqual(len(nodes), 2) | |
self.assertEqual(len(nodes[0].children), 1) | |
self.assertEqual(len(nodes[1].children), 0) | |
def test_show_menu_negative_level(self): | |
root = self.get_page(2) | |
context = self.get_context(page=root) | |
tpl = Template("{% load menu_tags %}{% show_menu -1 100 0 0 %}") | |
tpl.render(context) | |
nodes = context["children"] | |
# Expecting no children for negative level, or specific behavior depending on implementation | |
self.assertIsInstance(nodes, list) | |
self.assertEqual(len(nodes), 0) | |
def test_show_menu_positive_level_no_children(self): | |
# Create a page with no children | |
root = self.get_page(3) | |
context = self.get_context(page=root) | |
tpl = Template("{% load menu_tags %}{% show_menu 2 100 0 0 %}") | |
tpl.render(context) | |
nodes = context["children"] | |
self.assertIsInstance(nodes, list) | |
self.assertEqual(len(nodes), 0) |
It can be less than zero when the from_level is greater than zero.
Description
Related resources
Checklist
main
Summary by Sourcery
Fix cut_after to remove children for nodes when levels is less than or equal to zero and add tests to verify this behavior
Bug Fixes:
Tests: