Simplified a test by using CapturedQueriesContext
This commit is contained in:
parent
671757b507
commit
068b1e045f
|
@ -6,14 +6,13 @@ from operator import attrgetter
|
||||||
import pickle
|
import pickle
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
from django.db import DatabaseError, connection, connections, DEFAULT_DB_ALIAS
|
from django.db import DatabaseError, connection, connections, DEFAULT_DB_ALIAS
|
||||||
from django.db.models import Count, F, Q
|
from django.db.models import Count, F, Q
|
||||||
from django.db.models.sql.where import WhereNode, EverythingNode, NothingNode
|
from django.db.models.sql.where import WhereNode, EverythingNode, NothingNode
|
||||||
from django.db.models.sql.datastructures import EmptyResultSet
|
from django.db.models.sql.datastructures import EmptyResultSet
|
||||||
from django.test import TestCase, skipUnlessDBFeature
|
from django.test import TestCase, skipUnlessDBFeature
|
||||||
from django.test.utils import str_prefix
|
from django.test.utils import str_prefix, CaptureQueriesContext
|
||||||
from django.utils import six
|
from django.utils import six
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
|
@ -1848,16 +1847,14 @@ class ComparisonTests(TestCase):
|
||||||
|
|
||||||
|
|
||||||
class ExistsSql(TestCase):
|
class ExistsSql(TestCase):
|
||||||
def setUp(self):
|
|
||||||
settings.DEBUG = True
|
|
||||||
|
|
||||||
def test_exists(self):
|
def test_exists(self):
|
||||||
|
with CaptureQueriesContext(connection) as captured_queries:
|
||||||
self.assertFalse(Tag.objects.exists())
|
self.assertFalse(Tag.objects.exists())
|
||||||
# Ok - so the exist query worked - but did it include too many columns?
|
# Ok - so the exist query worked - but did it include too many columns?
|
||||||
self.assertTrue("id" not in connection.queries[-1]['sql'] and "name" not in connection.queries[-1]['sql'])
|
self.assertEqual(len(captured_queries), 1)
|
||||||
|
qstr = captured_queries[0]
|
||||||
def tearDown(self):
|
id, name = connection.ops.quote_name('id'), connection.ops.quote_name('name')
|
||||||
settings.DEBUG = False
|
self.assertTrue(id not in qstr and name not in qstr)
|
||||||
|
|
||||||
|
|
||||||
class QuerysetOrderedTests(unittest.TestCase):
|
class QuerysetOrderedTests(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue