Skip to content

Commit

Permalink
added test for #1145
Browse files Browse the repository at this point in the history
fixed tests that fail because of #1145
  • Loading branch information
ojii committed Jan 21, 2012
1 parent e204eac commit 3ae1ed2
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions cms/tests/menu.py
Expand Up @@ -10,15 +10,15 @@
from cms.test_utils.util.context_managers import (SettingsOverride,
LanguageOverride)
from cms.test_utils.util.mock import AttributeObject
from menus.base import NavigationNode
from menus.menu_pool import menu_pool, _build_nodes_inner_for_one_menu
from menus.utils import mark_descendants, find_selected, cut_levels

from django.conf import settings
from django.contrib.auth.models import AnonymousUser, User, Permission, Group
from django.contrib.contenttypes.models import ContentType
from django.contrib.sites.models import Site
from django.template import Template, TemplateSyntaxError
from menus.base import NavigationNode
from menus.menu_pool import menu_pool, _build_nodes_inner_for_one_menu
from menus.models import CacheKey
from menus.utils import mark_descendants, find_selected, cut_levels



class BaseMenuTest(SettingsOverrideTestCase):
Expand Down Expand Up @@ -112,16 +112,26 @@ def test_show_menu(self):
def test_show_menu_num_queries(self):
context = self.get_context()
# test standard show_menu
with self.assertNumQueries(4):
with self.assertNumQueries(5):
"""
The 4 queries should be:
get all pages
get all page permissions
get all titles
get the menu cache key
set the menu cache key
"""
tpl = Template("{% load menu_tags %}{% show_menu %}")
tpl.render(context)

def test_show_menu_cache_key_leak(self):
context = self.get_context()
tpl = Template("{% load menu_tags %}{% show_menu %}")
self.assertEqual(CacheKey.objects.count(), 0)
tpl.render(context)
self.assertEqual(CacheKey.objects.count(), 1)
tpl.render(context)
self.assertEqual(CacheKey.objects.count(), 1)

def test_only_active_tree(self):
context = self.get_context()
Expand Down Expand Up @@ -666,12 +676,13 @@ def test_show_submenu_num_queries(self):
page = Page.objects.get(title_set__title='P6')
context = self.get_context(page.get_absolute_url())
# test standard show_menu
with self.assertNumQueries(4):
with self.assertNumQueries(5):
"""
The 4 queries should be:
get all pages
get all page permissions
get all titles
get the menu cache key
set the menu cache key
"""
tpl = Template("{% load menu_tags %}{% show_sub_menu %}")
Expand Down Expand Up @@ -724,18 +735,19 @@ def test_not_in_navigation_num_queries(self):
in_navigation=True, reverse_id='a')
b =create_page('B', 'nav_playground.html', 'en', parent=a,
published=True, in_navigation=True)
c = create_page('C', 'nav_playground.html', 'en', parent=b,
create_page('C', 'nav_playground.html', 'en', parent=b,
published=True, in_navigation=True)
create_page('D', 'nav_playground.html', 'en', parent=self.reload(b),
published=True, in_navigation=False)
with LanguageOverride('en'):
context = self.get_context(a.get_absolute_url())
with self.assertNumQueries(4):
with self.assertNumQueries(5):
"""
The 4 queries should be:
get all pages
get all page permissions
get all titles
get the menu cache key
set the menu cache key
"""
# Actually seems to run:
Expand Down

0 comments on commit 3ae1ed2

Please sign in to comment.