1
0
mirror of https://github.com/django/django.git synced 2024-11-19 16:04:13 +00:00
django/tests/regressiontests/test_utils/python_25.py
2010-10-17 01:49:36 +00:00

29 lines
794 B
Python

from __future__ import with_statement
from django.test import TestCase
from models import Person
class AssertNumQueriesTests(TestCase):
def test_simple(self):
with self.assertNumQueries(0):
pass
with self.assertNumQueries(1):
Person.objects.count()
with self.assertNumQueries(2):
Person.objects.count()
Person.objects.count()
def test_failure(self):
with self.assertRaises(AssertionError) as exc_info:
with self.assertNumQueries(2):
Person.objects.count()
self.assertEqual(str(exc_info.exception), "1 != 2 : 1 queries executed, 2 expected")
with self.assertRaises(TypeError):
with self.assertNumQueries(4000):
raise TypeError