1
0
mirror of https://github.com/django/django.git synced 2025-06-05 03:29:12 +00:00

Removed unnecessary usage of .extra() in tests.

This commit is contained in:
Simon Charette 2023-03-26 19:20:09 -04:00
parent ac5e56a47f
commit 5d539daa56
No known key found for this signature in database
2 changed files with 9 additions and 3 deletions

View File

@ -19,6 +19,7 @@ from django.db import (
from django.db.backends.base.base import BaseDatabaseWrapper from django.db.backends.base.base import BaseDatabaseWrapper
from django.db.backends.signals import connection_created from django.db.backends.signals import connection_created
from django.db.backends.utils import CursorWrapper from django.db.backends.utils import CursorWrapper
from django.db.models import Value
from django.db.models.sql.constants import CURSOR from django.db.models.sql.constants import CURSOR
from django.test import ( from django.test import (
TestCase, TestCase,
@ -84,8 +85,10 @@ class LastExecutedQueryTest(TestCase):
def test_query_encoding(self): def test_query_encoding(self):
"""last_executed_query() returns a string.""" """last_executed_query() returns a string."""
data = RawData.objects.filter(raw_data=b"\x00\x46 \xFE").extra( data = RawData.objects.filter(raw_data=b"\x00\x46 \xFE").annotate(
select={"föö": 1} **{
"föö": Value(1),
}
) )
sql, params = data.query.sql_with_params() sql, params = data.query.sql_with_params()
with data.query.get_compiler("default").execute_sql(CURSOR) as cursor: with data.query.get_compiler("default").execute_sql(CURSOR) as cursor:

View File

@ -53,6 +53,7 @@ from django.db.models import (
UUIDField, UUIDField,
Value, Value,
) )
from django.db.models.expressions import RawSQL
from django.db.models.fields.json import KT, KeyTextTransform from django.db.models.fields.json import KT, KeyTextTransform
from django.db.models.functions import ( from django.db.models.functions import (
Abs, Abs,
@ -774,7 +775,9 @@ class SchemaTests(TransactionTestCase):
field_type, connection.features.introspected_field_types["IntegerField"] field_type, connection.features.introspected_field_types["IntegerField"]
) )
# Make sure the values were transformed correctly # Make sure the values were transformed correctly
self.assertEqual(Author.objects.extra(where=["thing = 1"]).count(), 2) self.assertEqual(
Author.objects.filter(RawSQL("thing = %s", (1,), BooleanField())).count(), 2
)
def test_add_field_o2o_nullable(self): def test_add_field_o2o_nullable(self):
with connection.schema_editor() as editor: with connection.schema_editor() as editor: