1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Switch several assertNumQueries to use the context manager, which is much more beautiful.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16986 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Alex Gaynor
2011-10-14 17:03:08 +00:00
parent 6c91521902
commit 69e1e6187a
6 changed files with 35 additions and 60 deletions

View File

@@ -58,26 +58,23 @@ class GetUniqueCheckTests(unittest.TestCase):
class PerformUniqueChecksTest(TestCase):
def test_primary_key_unique_check_not_performed_when_adding_and_pk_not_specified(self):
# Regression test for #12560
def test():
with self.assertNumQueries(0):
mtv = ModelToValidate(number=10, name='Some Name')
setattr(mtv, '_adding', True)
mtv.full_clean()
self.assertNumQueries(0, test)
def test_primary_key_unique_check_performed_when_adding_and_pk_specified(self):
# Regression test for #12560
def test():
with self.assertNumQueries(1):
mtv = ModelToValidate(number=10, name='Some Name', id=123)
setattr(mtv, '_adding', True)
mtv.full_clean()
self.assertNumQueries(1, test)
def test_primary_key_unique_check_not_performed_when_not_adding(self):
# Regression test for #12132
def test():
with self.assertNumQueries(0):
mtv = ModelToValidate(number=10, name='Some Name')
mtv.full_clean()
self.assertNumQueries(0, test)
def test_unique_for_date(self):
p1 = Post.objects.create(title="Django 1.0 is released",