1
0
mirror of https://github.com/django/django.git synced 2025-07-05 02:09:13 +00:00

[1.2.X] Fixed a broken test introduced in [14786].

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14806 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor 2010-12-04 07:53:23 +00:00
parent cc48f66f73
commit 70383ccf68
2 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,7 @@
from datetime import date from datetime import date
from django.conf import settings
from django.db import connection
from django.db.models.sql.query import InvalidQuery from django.db.models.sql.query import InvalidQuery
from django.test import TestCase from django.test import TestCase
@ -53,6 +55,16 @@ class RawQueryTests(TestCase):
self.assertTrue(hasattr(result, annotation)) self.assertTrue(hasattr(result, annotation))
self.assertEqual(getattr(result, annotation), value) self.assertEqual(getattr(result, annotation), value)
def assert_num_queries(self, n, func, *args, **kwargs):
old_DEBUG = settings.DEBUG
settings.DEBUG = True
starting_queries = len(connection.queries)
try:
func(*args, **kwargs)
finally:
settings.DEBUG = old_DEBUG
self.assertEqual(starting_queries + n, len(connection.queries))
def testSimpleRawQuery(self): def testSimpleRawQuery(self):
""" """
Basic test of raw query with a simple database query Basic test of raw query with a simple database query
@ -219,6 +231,6 @@ class RawQueryTests(TestCase):
) )
def test_query_count(self): def test_query_count(self):
self.assertNumQueries(1, self.assert_num_queries(1,
list, Author.objects.raw("SELECT * FROM raw_query_author") list, Author.objects.raw("SELECT * FROM raw_query_author")
) )

View File

@ -21,7 +21,6 @@ class DeferRegressionTest(TestCase):
settings.DEBUG = old_DEBUG settings.DEBUG = old_DEBUG
self.assertEqual(starting_queries + n, len(connection.queries)) self.assertEqual(starting_queries + n, len(connection.queries))
def test_basic(self): def test_basic(self):
# Deferred fields should really be deferred and not accidentally use # Deferred fields should really be deferred and not accidentally use
# the field's default value just because they aren't passed to __init__ # the field's default value just because they aren't passed to __init__