Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use AssertNumQueries

  • Loading branch information...
commit 15dc7ebf1886a5dedff9b8a87bcebb63443a4976 1 parent ad6dd1e
@ojii authored
Showing with 9 additions and 13 deletions.
  1. +9 −13 cms/tests/menu.py
View
22 cms/tests/menu.py
@@ -8,7 +8,6 @@
from cms.test_utils.testcases import SettingsOverrideTestCase
from cms.test_utils.util.mock import AttributeObject
from django.conf import settings
-from django import db
from django.template import Template
from menus.base import NavigationNode
from menus.menu_pool import menu_pool, _build_nodes_inner_for_one_menu
@@ -82,10 +81,9 @@ def test_basic_cms_menu(self):
def test_show_menu(self):
context = self.get_context()
# test standard show_menu
- db.reset_queries()
- tpl = Template("{% load menu_tags %}{% show_menu %}")
- tpl.render(context)
- self.assertEqual(len(db.connection.queries), 1)
+ with self.assertNumQueries(1):
+ tpl = Template("{% load menu_tags %}{% show_menu %}")
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 2)
self.assertEqual(nodes[0].selected, True)
@@ -718,10 +716,9 @@ def test_show_submenu(self):
page = Page.objects.get(title_set__title='P6')
context = self.get_context(page.get_absolute_url())
# test standard show_menu
- db.reset_queries()
- tpl = Template("{% load menu_tags %}{% show_sub_menu %}")
- tpl.render(context)
- self.assertEqual(len(db.connection.queries), 19) # five less queries as expected
+ with self.assertNumQueries(19):
+ tpl = Template("{% load menu_tags %}{% show_sub_menu %}")
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0].id, 8)
@@ -747,10 +744,9 @@ def test_not_in_navigation(self):
create_page('D', 'nav_playground.html', 'en', parent=self.reload(b),
published=True, in_navigation=False)
context = self.get_context(a.get_absolute_url())
- db.reset_queries()
- tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' 0 100 100 100 %}")
- tpl.render(context)
- self.assertEqual(len(db.connection.queries), 11) # three less queries as expected
+ with self.assertNumQueries(11):
+ tpl = Template("{% load menu_tags %}{% show_menu_below_id 'a' 0 100 100 100 %}")
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 1, nodes)
node = nodes[0]
Please sign in to comment.
Something went wrong with that request. Please try again.