diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2010-10-12 03:33:19 +0000 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2010-10-12 03:33:19 +0000 |
| commit | 5506653b777d7547d21ea2d74e9588fb94314b77 (patch) | |
| tree | 34b6e6c3de02848bf793bd3088681ae29c44238d /tests/regressiontests/forms | |
| parent | ceef628c192127d5e231613bc280d68dc0927fa3 (diff) | |
Fixed #5416 -- Added TestCase.assertNumQueries, which tests that a given function executes the correct number of queries.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14183 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/forms')
| -rw-r--r-- | tests/regressiontests/forms/models.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py index 028ff9bad2..a4891df06e 100644 --- a/tests/regressiontests/forms/models.py +++ b/tests/regressiontests/forms/models.py @@ -1,10 +1,9 @@ # -*- coding: utf-8 -*- import datetime -import tempfile import shutil +import tempfile -from django.db import models, connection -from django.conf import settings +from django.db import models # Can't import as "forms" due to implementation details in the test suite (the # current file is called "forms" and is already imported). from django import forms as django_forms @@ -77,19 +76,13 @@ class TestTicket12510(TestCase): ''' It is not necessary to generate choices for ModelChoiceField (regression test for #12510). ''' def setUp(self): self.groups = [Group.objects.create(name=name) for name in 'abc'] - self.old_debug = settings.DEBUG - # turn debug on to get access to connection.queries - settings.DEBUG = True - - def tearDown(self): - settings.DEBUG = self.old_debug def test_choices_not_fetched_when_not_rendering(self): - initial_queries = len(connection.queries) - field = django_forms.ModelChoiceField(Group.objects.order_by('-name')) - self.assertEqual('a', field.clean(self.groups[0].pk).name) + def test(): + field = django_forms.ModelChoiceField(Group.objects.order_by('-name')) + self.assertEqual('a', field.clean(self.groups[0].pk).name) # only one query is required to pull the model from DB - self.assertEqual(initial_queries+1, len(connection.queries)) + self.assertNumQueries(1, test) class ModelFormCallableModelDefault(TestCase): def test_no_empty_option(self): |
