Skip to content

Commit

Permalink
fix: test_admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Yu committed Oct 30, 2024
1 parent d8768d9 commit 0d37570
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


from django.contrib import admin
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.contrib.messages import get_messages
from django.contrib.sites.models import Site
Expand Down Expand Up @@ -1377,6 +1378,16 @@ def test_menuitem_delete_view_item_with_children(self):
content
)

def get_permission(self, codename):
_list = codename.split('.')
app_label = ''
if len(_list) > 1:
app_label = _list[0]
codename = _list[1]
return Permission.objects.get(codename=codename, content_type__app_label=app_label)
else:
return Permission.objects.get(codename=codename)

def test_menuitem_delete_view_with_permission(self):
"""
With appropriate permissions, the delete view allows deletion of Menuitems
Expand All @@ -1385,14 +1396,17 @@ def test_menuitem_delete_view_with_permission(self):
"user_with_delete", is_staff=True
)
menu_content = factories.MenuContentWithVersionFactory(version__created_by=user_with_delete_permissions)
child = factories.ChildMenuItemFactory(parent=menu_content.root)
new_child = factories.ChildMenuItemFactory(parent=menu_content.root)
child_of_child = factories.ChildMenuItemFactory(parent=child)
factories.ChildMenuItemFactory(parent=child_of_child)
child = factories.ChildMenuItemFactory(title="child", parent=menu_content.root)
new_child = factories.ChildMenuItemFactory(title="new_child", parent=menu_content.root)
child_of_child = factories.ChildMenuItemFactory(title="child_of_child", parent=child)
factories.ChildMenuItemFactory(title="child_of_child_2", parent=child_of_child)

self.add_permission(user_with_delete_permissions, "view_menucontentversion")
self.add_permission(user_with_delete_permissions, "delete_menuitem")

if CMS_41:
self.add_permission(user_with_delete_permissions, "djangocms_versioning.delete_versionlock")

# Delete one, editable node, with no children
delete_url_single = reverse(
"admin:djangocms_navigation_menuitem_delete", args=(menu_content.id, new_child.id,)
Expand Down

0 comments on commit 0d37570

Please sign in to comment.