mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #14774 -- the test client and assertNumQueries didn't work well together. Thanks to Jonas Obrist for the initial patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15251 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
53dac996ef
commit
8308ad4f05
6 changed files with 70 additions and 12 deletions
|
@ -2,20 +2,13 @@ import sys
|
|||
|
||||
from django.test import TestCase, skipUnlessDBFeature, skipIfDBFeature
|
||||
|
||||
from models import Person
|
||||
|
||||
if sys.version_info >= (2, 5):
|
||||
from tests_25 import AssertNumQueriesTests
|
||||
from tests_25 import AssertNumQueriesContextManagerTests
|
||||
|
||||
|
||||
class SkippingTestCase(TestCase):
|
||||
def test_assert_num_queries(self):
|
||||
def test_func():
|
||||
raise ValueError
|
||||
|
||||
self.assertRaises(ValueError,
|
||||
self.assertNumQueries, 2, test_func
|
||||
)
|
||||
|
||||
def test_skip_unless_db_feature(self):
|
||||
"A test that might be skipped is actually called."
|
||||
# Total hack, but it works, just want an attribute that's always true.
|
||||
|
@ -26,8 +19,37 @@ class SkippingTestCase(TestCase):
|
|||
self.assertRaises(ValueError, test_func)
|
||||
|
||||
|
||||
class SaveRestoreWarningState(TestCase):
|
||||
class AssertNumQueriesTests(TestCase):
|
||||
def test_assert_num_queries(self):
|
||||
def test_func():
|
||||
raise ValueError
|
||||
|
||||
self.assertRaises(ValueError,
|
||||
self.assertNumQueries, 2, test_func
|
||||
)
|
||||
|
||||
def test_assert_num_queries_with_client(self):
|
||||
person = Person.objects.create(name='test')
|
||||
|
||||
self.assertNumQueries(
|
||||
1,
|
||||
self.client.get,
|
||||
"/test_utils/get_person/%s/" % person.pk
|
||||
)
|
||||
|
||||
self.assertNumQueries(
|
||||
1,
|
||||
self.client.get,
|
||||
"/test_utils/get_person/%s/" % person.pk
|
||||
)
|
||||
|
||||
def test_func():
|
||||
self.client.get("/test_utils/get_person/%s/" % person.pk)
|
||||
self.client.get("/test_utils/get_person/%s/" % person.pk)
|
||||
self.assertNumQueries(2, test_func)
|
||||
|
||||
|
||||
class SaveRestoreWarningState(TestCase):
|
||||
def test_save_restore_warnings_state(self):
|
||||
"""
|
||||
Ensure save_warnings_state/restore_warnings_state work correctly.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue