-
-
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
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
It can be less than zero when the from_level is greater than zero.
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdate cut_after to remove children at non-positive levels and add a test verifying show_menu cuts inactive node children correctly. Class diagram for updated cut_after function in menu nodeclassDiagram
class Node {
children: list[Node]
}
class MenuTags {
+cut_after(node: Node, levels: int)
}
MenuTags --> Node: operates on
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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 and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## 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 assertions for edge cases with level=0 and negative levels.
Adding assertions for level=0 and negative values will help verify the function's behavior for all edge cases.
</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)
# Standard case
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)
# Edge case: level=0
tpl_zero = Template("{% load menu_tags %}{% show_menu 0 100 0 1 %}")
tpl_zero.render(context)
nodes_zero = context["children"]
# Assert that nodes_zero is not empty and has expected structure
self.assertTrue(isinstance(nodes_zero, list))
self.assertGreaterEqual(len(nodes_zero), 0)
# Edge case: negative level
tpl_negative = Template("{% load menu_tags %}{% show_menu -1 100 0 1 %}")
# Depending on implementation, this may raise an error or return empty list
try:
tpl_negative.render(context)
nodes_negative = context["children"]
self.assertTrue(isinstance(nodes_negative, list))
self.assertEqual(len(nodes_negative), 0)
except Exception as e:
self.assertIsInstance(e, Exception)
>>>>>>> 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 assertions for edge cases with level=0 and negative levels.
Adding assertions for level=0 and negative values will help verify the function's behavior for all edge cases.
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) | |
# Standard case | |
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) | |
# Edge case: level=0 | |
tpl_zero = Template("{% load menu_tags %}{% show_menu 0 100 0 1 %}") | |
tpl_zero.render(context) | |
nodes_zero = context["children"] | |
# Assert that nodes_zero is not empty and has expected structure | |
self.assertTrue(isinstance(nodes_zero, list)) | |
self.assertGreaterEqual(len(nodes_zero), 0) | |
# Edge case: negative level | |
tpl_negative = Template("{% load menu_tags %}{% show_menu -1 100 0 1 %}") | |
# Depending on implementation, this may raise an error or return empty list | |
try: | |
tpl_negative.render(context) | |
nodes_negative = context["children"] | |
self.assertTrue(isinstance(nodes_negative, list)) | |
self.assertEqual(len(nodes_negative), 0) | |
except Exception as e: | |
self.assertIsInstance(e, Exception) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8322 +/- ##
=======================================
Coverage 89.69% 89.69%
=======================================
Files 129 129
Lines 12733 12733
=======================================
Hits 11421 11421
Misses 1312 1312 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Nice work! Thank you!
#8322) It can be less than zero when the from_level is greater than zero. Co-authored-by: Fabian Braun <[email protected]>
#8322) (#8324) It can be less than zero when the from_level is greater than zero. Co-authored-by: Stefan Wehrmeyer <[email protected]>
Description
Fixes #8321 and adds a test.
Related resources
Checklist
main
Summary by Sourcery
Fix the cut_after logic to remove children when levels is non-positive and add a test to verify inactive nodes have no children at non-positive levels
Bug Fixes:
Tests: