summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNick Pope <nick.pope@flightdataservices.com>2019-08-20 08:54:41 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-02-04 13:20:06 +0100
commit335c9c94acf263901fb023404408880245b0c4b4 (patch)
tree691e9683de6c9840cd0a9a097d020c499ea735db /tests
parent469bf2db15597f2c87cb0f8f64132056d2467f15 (diff)
Simplified imports from django.db and django.contrib.gis.db.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_changelist/tests.py3
-rw-r--r--tests/aggregation/tests.py5
-rw-r--r--tests/aggregation_regress/tests.py5
-rw-r--r--tests/backends/mysql/test_creation.py3
-rw-r--r--tests/backends/oracle/test_creation.py3
-rw-r--r--tests/backends/oracle/tests.py5
-rw-r--r--tests/backends/postgresql/test_creation.py3
-rw-r--r--tests/backends/sqlite/tests.py8
-rw-r--r--tests/backends/test_utils.py3
-rw-r--r--tests/basic/tests.py8
-rw-r--r--tests/db_functions/comparison/test_cast.py6
-rw-r--r--tests/db_functions/text/test_sha224.py3
-rw-r--r--tests/db_utils/tests.py4
-rw-r--r--tests/delete/tests.py5
-rw-r--r--tests/expressions/test_queryset_values.py3
-rw-r--r--tests/expressions/tests.py124
-rw-r--r--tests/expressions_case/tests.py174
-rw-r--r--tests/expressions_window/tests.py5
-rw-r--r--tests/foreign_object/models/customers.py5
-rw-r--r--tests/foreign_object/models/empty_join.py6
-rw-r--r--tests/foreign_object/tests.py5
-rw-r--r--tests/generic_relations_regress/models.py3
-rw-r--r--tests/generic_relations_regress/tests.py5
-rw-r--r--tests/gis_tests/test_fields.py2
-rw-r--r--tests/gis_tests/test_gis_tests_utils.py3
-rw-r--r--tests/gis_tests/utils.py2
-rw-r--r--tests/indexes/tests.py5
-rw-r--r--tests/introspection/tests.py3
-rw-r--r--tests/invalid_models_tests/test_relative_fields.py9
-rw-r--r--tests/lookup/test_decimalfield.py3
-rw-r--r--tests/lookup/test_lookups.py3
-rw-r--r--tests/lookup/tests.py3
-rw-r--r--tests/many_to_one/tests.py3
-rw-r--r--tests/migrations/test_executor.py3
-rw-r--r--tests/migrations/test_operations.py8
-rw-r--r--tests/model_fields/models.py15
-rw-r--r--tests/model_fields/test_field_flags.py26
-rw-r--r--tests/model_fields/test_filefield.py2
-rw-r--r--tests/model_fields/test_promises.py12
-rw-r--r--tests/model_indexes/tests.py9
-rw-r--r--tests/model_meta/tests.py10
-rw-r--r--tests/ordering/models.py3
-rw-r--r--tests/postgres_tests/test_aggregates.py3
-rw-r--r--tests/postgres_tests/test_constraints.py6
-rw-r--r--tests/postgres_tests/test_hstore.py3
-rw-r--r--tests/postgres_tests/test_indexes.py6
-rw-r--r--tests/postgres_tests/test_operations.py5
-rw-r--r--tests/prefetch_related/models.py4
-rw-r--r--tests/prefetch_related/tests.py4
-rw-r--r--tests/queries/test_qs_combinators.py3
-rw-r--r--tests/schema/fields.py16
-rw-r--r--tests/schema/tests.py20
52 files changed, 268 insertions, 320 deletions
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index 933d2ac1d2..fa0c08669d 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -10,8 +10,7 @@ from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.messages.storage.cookie import CookieStorage
from django.db import connection, models
-from django.db.models import F
-from django.db.models.fields import Field, IntegerField
+from django.db.models import F, Field, IntegerField
from django.db.models.functions import Upper
from django.db.models.lookups import Contains, Exact
from django.template import Context, Template, TemplateSyntaxError
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py
index 62b47ebd1c..ed2125c0a9 100644
--- a/tests/aggregation/tests.py
+++ b/tests/aggregation/tests.py
@@ -5,10 +5,9 @@ from decimal import Decimal
from django.core.exceptions import FieldError
from django.db import connection
from django.db.models import (
- Avg, Count, DecimalField, DurationField, F, FloatField, Func, IntegerField,
- Max, Min, Sum, Value,
+ Avg, Case, Count, DecimalField, DurationField, Exists, F, FloatField, Func,
+ IntegerField, Max, Min, OuterRef, Subquery, Sum, Value, When,
)
-from django.db.models.expressions import Case, Exists, OuterRef, Subquery, When
from django.db.models.functions import Coalesce
from django.test import TestCase
from django.test.testcases import skipUnlessDBFeature
diff --git a/tests/aggregation_regress/tests.py b/tests/aggregation_regress/tests.py
index 63e51fea2e..bdfcb1d89b 100644
--- a/tests/aggregation_regress/tests.py
+++ b/tests/aggregation_regress/tests.py
@@ -8,10 +8,9 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import FieldError
from django.db import connection
from django.db.models import (
- Avg, Case, Count, DecimalField, F, IntegerField, Max, Q, StdDev, Sum,
- Value, Variance, When,
+ Aggregate, Avg, Case, Count, DecimalField, F, IntegerField, Max, Q, StdDev,
+ Sum, Value, Variance, When,
)
-from django.db.models.aggregates import Aggregate
from django.test import TestCase, skipUnlessAnyDBFeature, skipUnlessDBFeature
from django.test.utils import Approximate
diff --git a/tests/backends/mysql/test_creation.py b/tests/backends/mysql/test_creation.py
index 01e59d8758..5675601a1b 100644
--- a/tests/backends/mysql/test_creation.py
+++ b/tests/backends/mysql/test_creation.py
@@ -3,10 +3,9 @@ import unittest
from io import StringIO
from unittest import mock
-from django.db import connection
+from django.db import DatabaseError, connection
from django.db.backends.base.creation import BaseDatabaseCreation
from django.db.backends.mysql.creation import DatabaseCreation
-from django.db.utils import DatabaseError
from django.test import SimpleTestCase
diff --git a/tests/backends/oracle/test_creation.py b/tests/backends/oracle/test_creation.py
index f090a0ac89..930d2520e2 100644
--- a/tests/backends/oracle/test_creation.py
+++ b/tests/backends/oracle/test_creation.py
@@ -2,9 +2,8 @@ import unittest
from io import StringIO
from unittest import mock
-from django.db import connection
+from django.db import DatabaseError, connection
from django.db.backends.oracle.creation import DatabaseCreation
-from django.db.utils import DatabaseError
from django.test import TestCase
diff --git a/tests/backends/oracle/tests.py b/tests/backends/oracle/tests.py
index a0d49854d9..0a7bf01963 100644
--- a/tests/backends/oracle/tests.py
+++ b/tests/backends/oracle/tests.py
@@ -1,8 +1,7 @@
import unittest
-from django.db import connection
-from django.db.models.fields import BooleanField, NullBooleanField
-from django.db.utils import DatabaseError
+from django.db import DatabaseError, connection
+from django.db.models import BooleanField, NullBooleanField
from django.test import TransactionTestCase
from ..models import Square
diff --git a/tests/backends/postgresql/test_creation.py b/tests/backends/postgresql/test_creation.py
index 7d6f319a80..f6a067248d 100644
--- a/tests/backends/postgresql/test_creation.py
+++ b/tests/backends/postgresql/test_creation.py
@@ -3,9 +3,8 @@ from contextlib import contextmanager
from io import StringIO
from unittest import mock
-from django.db import connection
+from django.db import DatabaseError, connection
from django.db.backends.base.creation import BaseDatabaseCreation
-from django.db.utils import DatabaseError
from django.test import SimpleTestCase
try:
diff --git a/tests/backends/sqlite/tests.py b/tests/backends/sqlite/tests.py
index 3447fb6096..fc02671ca5 100644
--- a/tests/backends/sqlite/tests.py
+++ b/tests/backends/sqlite/tests.py
@@ -8,11 +8,9 @@ from sqlite3 import dbapi2
from unittest import mock
from django.core.exceptions import ImproperlyConfigured
-from django.db import ConnectionHandler, connection, transaction
-from django.db.models import Avg, StdDev, Sum, Variance
-from django.db.models.aggregates import Aggregate
-from django.db.models.fields import CharField
-from django.db.utils import NotSupportedError
+from django.db import NotSupportedError, connection, transaction
+from django.db.models import Aggregate, Avg, CharField, StdDev, Sum, Variance
+from django.db.utils import ConnectionHandler
from django.test import (
TestCase, TransactionTestCase, override_settings, skipIfDBFeature,
)
diff --git a/tests/backends/test_utils.py b/tests/backends/test_utils.py
index cd4911fd1a..7974dee607 100644
--- a/tests/backends/test_utils.py
+++ b/tests/backends/test_utils.py
@@ -1,11 +1,10 @@
"""Tests for django.db.backends.utils"""
from decimal import Decimal, Rounded
-from django.db import connection
+from django.db import NotSupportedError, connection
from django.db.backends.utils import (
format_number, split_identifier, truncate_name,
)
-from django.db.utils import NotSupportedError
from django.test import (
SimpleTestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature,
)
diff --git a/tests/basic/tests.py b/tests/basic/tests.py
index 5eada343e1..e186958400 100644
--- a/tests/basic/tests.py
+++ b/tests/basic/tests.py
@@ -5,7 +5,7 @@ from unittest import mock
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.db import DEFAULT_DB_ALIAS, DatabaseError, connections, models
from django.db.models.manager import BaseManager
-from django.db.models.query import MAX_GET_RESULTS, EmptyQuerySet, QuerySet
+from django.db.models.query import MAX_GET_RESULTS, EmptyQuerySet
from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, skipUnlessDBFeature,
)
@@ -316,7 +316,7 @@ class ModelTest(TestCase):
# A hacky test for custom QuerySet subclass - refs #17271
Article.objects.create(headline='foo', pub_date=datetime.now())
- class CustomQuerySet(QuerySet):
+ class CustomQuerySet(models.QuerySet):
def do_something(self):
return 'did something'
@@ -607,7 +607,7 @@ class ManagerTest(SimpleTestCase):
`Manager` will need to be added to `ManagerTest.QUERYSET_PROXY_METHODS`.
"""
self.assertEqual(
- sorted(BaseManager._get_queryset_methods(QuerySet)),
+ sorted(BaseManager._get_queryset_methods(models.QuerySet)),
sorted(self.QUERYSET_PROXY_METHODS),
)
@@ -640,7 +640,7 @@ class SelectOnSaveTests(TestCase):
orig_class = Article._base_manager._queryset_class
- class FakeQuerySet(QuerySet):
+ class FakeQuerySet(models.QuerySet):
# Make sure the _update method below is in fact called.
called = False
diff --git a/tests/db_functions/comparison/test_cast.py b/tests/db_functions/comparison/test_cast.py
index c08e61a9e6..a286e467a0 100644
--- a/tests/db_functions/comparison/test_cast.py
+++ b/tests/db_functions/comparison/test_cast.py
@@ -3,8 +3,6 @@ import decimal
import unittest
from django.db import connection, models
-from django.db.models import Avg
-from django.db.models.expressions import Value
from django.db.models.functions import Cast
from django.test import (
TestCase, ignore_warnings, override_settings, skipUnlessDBFeature,
@@ -19,7 +17,7 @@ class CastTests(TestCase):
Author.objects.create(name='Bob', age=1, alias='1')
def test_cast_from_value(self):
- numbers = Author.objects.annotate(cast_integer=Cast(Value('0'), models.IntegerField()))
+ numbers = Author.objects.annotate(cast_integer=Cast(models.Value('0'), models.IntegerField()))
self.assertEqual(numbers.get().cast_integer, 0)
def test_cast_from_field(self):
@@ -127,7 +125,7 @@ class CastTests(TestCase):
The SQL for the Cast expression is wrapped with parentheses in case
it's a complex expression.
"""
- list(Author.objects.annotate(cast_float=Cast(Avg('age'), models.FloatField())))
+ list(Author.objects.annotate(cast_float=Cast(models.Avg('age'), models.FloatField())))
self.assertIn('(AVG("db_functions_author"."age"))::double precision', connection.queries[-1]['sql'])
def test_cast_to_text_field(self):
diff --git a/tests/db_functions/text/test_sha224.py b/tests/db_functions/text/test_sha224.py
index 9ec0bf933f..a8291d416c 100644
--- a/tests/db_functions/text/test_sha224.py
+++ b/tests/db_functions/text/test_sha224.py
@@ -1,9 +1,8 @@
import unittest
-from django.db import connection
+from django.db import NotSupportedError, connection
from django.db.models import CharField
from django.db.models.functions import SHA224
-from django.db.utils import NotSupportedError
from django.test import TestCase
from django.test.utils import register_lookup
diff --git a/tests/db_utils/tests.py b/tests/db_utils/tests.py
index db58b58f33..2a1cec0365 100644
--- a/tests/db_utils/tests.py
+++ b/tests/db_utils/tests.py
@@ -2,8 +2,8 @@
import unittest
from django.core.exceptions import ImproperlyConfigured
-from django.db import DEFAULT_DB_ALIAS, connection
-from django.db.utils import ConnectionHandler, ProgrammingError, load_backend
+from django.db import DEFAULT_DB_ALIAS, ProgrammingError, connection
+from django.db.utils import ConnectionHandler, load_backend
from django.test import SimpleTestCase, TestCase
diff --git a/tests/delete/tests.py b/tests/delete/tests.py
index 1731342bc1..d8424670c9 100644
--- a/tests/delete/tests.py
+++ b/tests/delete/tests.py
@@ -1,9 +1,8 @@
from math import ceil
from django.db import connection, models
-from django.db.models.deletion import (
- Collector, ProtectedError, RestrictedError,
-)
+from django.db.models import ProtectedError, RestrictedError
+from django.db.models.deletion import Collector
from django.db.models.sql.constants import GET_ITERATOR_CHUNK_SIZE
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
diff --git a/tests/expressions/test_queryset_values.py b/tests/expressions/test_queryset_values.py
index e264597968..a15cc26023 100644
--- a/tests/expressions/test_queryset_values.py
+++ b/tests/expressions/test_queryset_values.py
@@ -1,5 +1,4 @@
-from django.db.models.aggregates import Sum
-from django.db.models.expressions import F
+from django.db.models import F, Sum
from django.test import TestCase
from .models import Company, Employee
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index 180153f555..6f1a9723e8 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -6,16 +6,14 @@ from copy import deepcopy
from unittest import mock
from django.core.exceptions import FieldError
-from django.db import DatabaseError, connection, models
-from django.db.models import CharField, Q, TimeField, UUIDField
-from django.db.models.aggregates import (
- Avg, Count, Max, Min, StdDev, Sum, Variance,
-)
-from django.db.models.expressions import (
- Case, Col, Combinable, Exists, Expression, ExpressionList,
- ExpressionWrapper, F, Func, OrderBy, OuterRef, Random, RawSQL, Ref,
- Subquery, Value, When,
+from django.db import DatabaseError, connection
+from django.db.models import (
+ Avg, BooleanField, Case, CharField, Count, DateField, DateTimeField,
+ DurationField, Exists, Expression, ExpressionList, ExpressionWrapper, F,
+ Func, IntegerField, Max, Min, Model, OrderBy, OuterRef, Q, StdDev,
+ Subquery, Sum, TimeField, UUIDField, Value, Variance, When,
)
+from django.db.models.expressions import Col, Combinable, Random, RawSQL, Ref
from django.db.models.functions import (
Coalesce, Concat, Length, Lower, Substr, Upper,
)
@@ -57,7 +55,7 @@ class BasicExpressionsTests(TestCase):
).values('num_employees', 'salaries').aggregate(
result=Sum(
F('salaries') + F('num_employees'),
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
)
self.assertEqual(companies['result'], 2395)
@@ -79,7 +77,7 @@ class BasicExpressionsTests(TestCase):
def test_filtering_on_annotate_that_uses_q(self):
self.assertEqual(
Company.objects.annotate(
- num_employees_check=ExpressionWrapper(Q(num_employees__gt=3), output_field=models.BooleanField())
+ num_employees_check=ExpressionWrapper(Q(num_employees__gt=3), output_field=BooleanField())
).filter(num_employees_check=True).count(),
2,
)
@@ -87,7 +85,7 @@ class BasicExpressionsTests(TestCase):
def test_filtering_on_q_that_is_boolean(self):
self.assertEqual(
Company.objects.filter(
- ExpressionWrapper(Q(num_employees__gt=3), output_field=models.BooleanField())
+ ExpressionWrapper(Q(num_employees__gt=3), output_field=BooleanField())
).count(),
2,
)
@@ -95,7 +93,7 @@ class BasicExpressionsTests(TestCase):
def test_filtering_on_rawsql_that_is_boolean(self):
self.assertEqual(
Company.objects.filter(
- RawSQL('num_employees > %s', (3,), output_field=models.BooleanField()),
+ RawSQL('num_employees > %s', (3,), output_field=BooleanField()),
).count(),
2,
)
@@ -438,7 +436,7 @@ class BasicExpressionsTests(TestCase):
def test_exist_single_field_output_field(self):
queryset = Company.objects.values('pk')
- self.assertIsInstance(Exists(queryset).output_field, models.BooleanField)
+ self.assertIsInstance(Exists(queryset).output_field, BooleanField)
def test_subquery(self):
Company.objects.filter(name='Example Inc.').update(
@@ -452,8 +450,8 @@ class BasicExpressionsTests(TestCase):
is_ceo_of_small_company=Exists(Company.objects.filter(num_employees__lt=200, ceo=OuterRef('pk'))),
is_ceo_small_2=~~Exists(Company.objects.filter(num_employees__lt=200, ceo=OuterRef('pk'))),
largest_company=Subquery(Company.objects.order_by('-num_employees').filter(
- models.Q(ceo=OuterRef('pk')) | models.Q(point_of_contact=OuterRef('pk'))
- ).values('name')[:1], output_field=models.CharField())
+ Q(ceo=OuterRef('pk')) | Q(point_of_contact=OuterRef('pk'))
+ ).values('name')[:1], output_field=CharField())
).values(
'firstname',
'is_point_of_contact',
@@ -533,7 +531,7 @@ class BasicExpressionsTests(TestCase):
contrived = Employee.objects.annotate(
is_point_of_contact=Subquery(
outer.filter(pk=OuterRef('pk')).values('is_point_of_contact'),
- output_field=models.BooleanField(),
+ output_field=BooleanField(),
),
)
self.assertCountEqual(contrived.values_list(), outer.values_list())
@@ -564,7 +562,7 @@ class BasicExpressionsTests(TestCase):
])
inner = Time.objects.filter(time=OuterRef(OuterRef('time')), pk=OuterRef('start')).values('time')
middle = SimulationRun.objects.annotate(other=Subquery(inner)).values('other')[:1]
- outer = Time.objects.annotate(other=Subquery(middle, output_field=models.TimeField()))
+ outer = Time.objects.annotate(other=Subquery(middle, output_field=TimeField()))
# This is a contrived example. It exercises the double OuterRef form.
self.assertCountEqual(outer, [first, second, third])
@@ -574,7 +572,7 @@ class BasicExpressionsTests(TestCase):
SimulationRun.objects.create(start=first, end=second, midpoint='12:00')
inner = SimulationRun.objects.filter(start=OuterRef(OuterRef('pk'))).values('start')
middle = Time.objects.annotate(other=Subquery(inner)).values('other')[:1]
- outer = Time.objects.annotate(other=Subquery(middle, output_field=models.IntegerField()))
+ outer = Time.objects.annotate(other=Subquery(middle, output_field=IntegerField()))
# This exercises the double OuterRef form with AutoField as pk.
self.assertCountEqual(outer, [first, second])
@@ -582,7 +580,7 @@ class BasicExpressionsTests(TestCase):
Company.objects.filter(num_employees__lt=50).update(ceo=Employee.objects.get(firstname='Frank'))
inner = Company.objects.filter(
ceo=OuterRef('pk')
- ).values('ceo').annotate(total_employees=models.Sum('num_employees')).values('total_employees')
+ ).values('ceo').annotate(total_employees=Sum('num_employees')).values('total_employees')
outer = Employee.objects.annotate(total_employees=Subquery(inner)).filter(salary__lte=Subquery(inner))
self.assertSequenceEqual(
outer.order_by('-total_employees').values('salary', 'total_employees'),
@@ -632,7 +630,7 @@ class BasicExpressionsTests(TestCase):
def test_explicit_output_field(self):
class FuncA(Func):
- output_field = models.CharField()
+ output_field = CharField()
class FuncB(Func):
pass
@@ -656,13 +654,13 @@ class BasicExpressionsTests(TestCase):
Company.objects.annotate(
salary_raise=OuterRef('num_employees') + F('num_employees'),
).order_by('-salary_raise').values('salary_raise')[:1],
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
),
).get(pk=self.gmbh.pk)
self.assertEqual(gmbh_salary.max_ceo_salary_raise, 2332)
def test_pickle_expression(self):
- expr = Value(1, output_field=models.IntegerField())
+ expr = Value(1, output_field=IntegerField())
expr.convert_value # populate cached property
self.assertEqual(pickle.loads(pickle.dumps(expr)), expr)
@@ -697,7 +695,7 @@ class BasicExpressionsTests(TestCase):
When(Exists(is_ceo), then=True),
When(Exists(is_poc), then=True),
default=False,
- output_field=models.BooleanField(),
+ output_field=BooleanField(),
),
)
self.assertSequenceEqual(qs, [self.example_inc.ceo, self.foobar_ltd.ceo, self.max])
@@ -986,18 +984,18 @@ class SimpleExpressionTests(SimpleTestCase):
def test_equal(self):
self.assertEqual(Expression(), Expression())
self.assertEqual(
- Expression(models.IntegerField()),
- Expression(output_field=models.IntegerField())
+ Expression(IntegerField()),
+ Expression(output_field=IntegerField())
)
- self.assertEqual(Expression(models.IntegerField()), mock.ANY)
+ self.assertEqual(Expression(IntegerField()), mock.ANY)
self.assertNotEqual(
- Expression(models.IntegerField()),
- Expression(models.CharField())
+ Expression(IntegerField()),
+ Expression(CharField())
)
- class TestModel(models.Model):
- field = models.IntegerField()
- other_field = models.IntegerField()
+ class TestModel(Model):
+ field = IntegerField()
+ other_field = IntegerField()
self.assertNotEqual(
Expression(TestModel._meta.get_field('field')),
@@ -1007,17 +1005,17 @@ class SimpleExpressionTests(SimpleTestCase):
def test_hash(self):
self.assertEqual(hash(Expression()), hash(Expression()))
self.assertEqual(
- hash(Expression(models.IntegerField())),
- hash(Expression(output_field=models.IntegerField()))
+ hash(Expression(IntegerField())),
+ hash(Expression(output_field=IntegerField()))
)
self.assertNotEqual(
- hash(Expression(models.IntegerField())),
- hash(Expression(models.CharField())),
+ hash(Expression(IntegerField())),
+ hash(Expression(CharField())),
)
- class TestModel(models.Model):
- field = models.IntegerField()
- other_field = models.IntegerField()
+ class TestModel(Model):
+ field = IntegerField()
+ other_field = IntegerField()
self.assertNotEqual(
hash(Expression(TestModel._meta.get_field('field'))),
@@ -1392,8 +1390,8 @@ class FTimeDeltaTests(TestCase):
self.assertEqual(delta_math, ['e4'])
queryset = Experiment.objects.annotate(shifted=ExpressionWrapper(
- F('start') + Value(None, output_field=models.DurationField()),
- output_field=models.DateTimeField(),
+ F('start') + Value(None, output_field=DurationField()),
+ output_field=DateTimeField(),
))
self.assertIsNone(queryset.first().shifted)
@@ -1401,7 +1399,7 @@ class FTimeDeltaTests(TestCase):
def test_date_subtraction(self):
queryset = Experiment.objects.annotate(
completion_duration=ExpressionWrapper(
- F('completed') - F('assigned'), output_field=models.DurationField()
+ F('completed') - F('assigned'), output_field=DurationField()
)
)
@@ -1415,14 +1413,14 @@ class FTimeDeltaTests(TestCase):
self.assertEqual(less_than_5_days, {'e0', 'e1', 'e2'})
queryset = Experiment.objects.annotate(difference=ExpressionWrapper(
- F('completed') - Value(None, output_field=models.DateField()),
- output_field=models.DurationField(),
+ F('completed') - Value(None, output_field=DateField()),
+ output_field=DurationField(),
))
self.assertIsNone(queryset.first().difference)
queryset = Experiment.objects.annotate(shifted=ExpressionWrapper(
- F('completed') - Value(None, output_field=models.DurationField()),
- output_field=models.DateField(),
+ F('completed') - Value(None, output_field=DurationField()),
+ output_field=DateField(),
))
self.assertIsNone(queryset.first().shifted)
@@ -1431,7 +1429,7 @@ class FTimeDeltaTests(TestCase):
subquery = Experiment.objects.filter(pk=OuterRef('pk')).values('completed')
queryset = Experiment.objects.annotate(
difference=ExpressionWrapper(
- subquery - F('completed'), output_field=models.DurationField(),
+ subquery - F('completed'), output_field=DurationField(),
),
).filter(difference=datetime.timedelta())
self.assertTrue(queryset.exists())
@@ -1441,8 +1439,8 @@ class FTimeDeltaTests(TestCase):
Time.objects.create(time=datetime.time(12, 30, 15, 2345))
queryset = Time.objects.annotate(
difference=ExpressionWrapper(
- F('time') - Value(datetime.time(11, 15, 0), output_field=models.TimeField()),
- output_field=models.DurationField(),
+ F('time') - Value(datetime.time(11, 15, 0), output_field=TimeField()),
+ output_field=DurationField(),
)
)
self.assertEqual(
@@ -1451,14 +1449,14 @@ class FTimeDeltaTests(TestCase):
)
queryset = Time.objects.annotate(difference=ExpressionWrapper(
- F('time') - Value(None, output_field=models.TimeField()),
- output_field=models.DurationField(),
+ F('time') - Value(None, output_field=TimeField()),
+ output_field=DurationField(),
))
self.assertIsNone(queryset.first().difference)
queryset = Time.objects.annotate(shifted=ExpressionWrapper(
- F('time') - Value(None, output_field=models.DurationField()),
- output_field=models.TimeField(),
+ F('time') - Value(None, output_field=DurationField()),
+ output_field=TimeField(),
))
self.assertIsNone(queryset.first().shifted)
@@ -1468,7 +1466,7 @@ class FTimeDeltaTests(TestCase):
subquery = Time.objects.filter(pk=OuterRef('pk')).values('time')
queryset = Time.objects.annotate(
difference=ExpressionWrapper(
- subquery - F('time'), output_field=models.DurationField(),
+ subquery - F('time'), output_field=DurationField(),
),
).filter(difference=datetime.timedelta())
self.assertTrue(queryset.exists())
@@ -1486,14 +1484,14 @@ class FTimeDeltaTests(TestCase):
self.assertEqual(over_estimate, ['e4'])
queryset = Experiment.objects.annotate(difference=ExpressionWrapper(
- F('start') - Value(None, output_field=models.DateTimeField()),
- output_field=models.DurationField(),
+ F('start') - Value(None, output_field=DateTimeField()),
+ output_field=DurationField(),
))
self.assertIsNone(queryset.first().difference)
queryset = Experiment.objects.annotate(shifted=ExpressionWrapper(
- F('start') - Value(None, output_field=models.DurationField()),
- output_field=models.DateTimeField(),
+ F('start') - Value(None, output_field=DurationField()),
+ output_field=DateTimeField(),
))
self.assertIsNone(queryset.first().shifted)
@@ -1502,7 +1500,7 @@ class FTimeDeltaTests(TestCase):
subquery = Experiment.objects.filter(pk=OuterRef('pk')).values('start')
queryset = Experiment.objects.annotate(
difference=ExpressionWrapper(
- subquery - F('start'), output_field=models.DurationField(),
+ subquery - F('start'), output_field=DurationField(),
),
).filter(difference=datetime.timedelta())
self.assertTrue(queryset.exists())
@@ -1512,7 +1510,7 @@ class FTimeDeltaTests(TestCase):
delta = datetime.timedelta(microseconds=8999999999999999)
Experiment.objects.update(end=F('start') + delta)
qs = Experiment.objects.annotate(
- delta=ExpressionWrapper(F('end') - F('start'), output_field=models.DurationField())
+ delta=ExpressionWrapper(F('end') - F('start'), output_field=DurationField())
)
for e in qs:
self.assertEqual(e.delta, delta)
@@ -1530,14 +1528,14 @@ class FTimeDeltaTests(TestCase):
delta = datetime.timedelta(microseconds=8999999999999999)
qs = Experiment.objects.annotate(dt=ExpressionWrapper(
F('start') + delta,
- output_field=models.DateTimeField(),
+ output_field=DateTimeField(),
))
for e in qs:
self.assertEqual(e.dt, e.start + delta)
def test_date_minus_duration(self):
more_than_4_days = Experiment.objects.filter(
- assigned__lt=F('completed') - Value(datetime.timedelta(days=4), output_field=models.DurationField())
+ assigned__lt=F('completed') - Value(datetime.timedelta(days=4), output_field=DurationField())
)
self.assertQuerysetEqual(more_than_4_days, ['e3', 'e4', 'e5'], lambda e: e.name)
@@ -1661,7 +1659,7 @@ class ReprTests(SimpleTestCase):
self.assertEqual(repr(F('published')), "F(published)")
self.assertEqual(repr(F('cost') + F('tax')), "<CombinedExpression: F(cost) + F(tax)>")
self.assertEqual(
- repr(ExpressionWrapper(F('cost') + F('tax'), models.IntegerField())),
+ repr(ExpressionWrapper(F('cost') + F('tax'), IntegerField())),
"ExpressionWrapper(F(cost) + F(tax))"
)
self.assertEqual(repr(Func('published', function='TO_CHAR')), "Func(F(published), function=TO_CHAR)")
diff --git a/tests/expressions_case/tests.py b/tests/expressions_case/tests.py
index d1a58f5d88..f85def932a 100644
--- a/tests/expressions_case/tests.py
+++ b/tests/expressions_case/tests.py
@@ -5,9 +5,11 @@ from operator import attrgetter, itemgetter
from uuid import UUID
from django.core.exceptions import FieldError
-from django.db import models
-from django.db.models import F, Max, Min, Q, Sum, Value
-from django.db.models.expressions import Case, When
+from django.db.models import (
+ BinaryField, Case, CharField, Count, DurationField, F,
+ GenericIPAddressField, IntegerField, Max, Min, Q, Sum, TextField,
+ TimeField, UUIDField, Value, When,
+)
from django.test import SimpleTestCase, TestCase
from .models import CaseTestModel, Client, FKCaseTestModel, O2OCaseTestModel
@@ -57,7 +59,7 @@ class CaseExpressionTests(TestCase):
# GROUP BY on Oracle fails with TextField/BinaryField; see #24096.
cls.non_lob_fields = [
f.name for f in CaseTestModel._meta.get_fields()
- if not (f.is_relation and f.auto_created) and not isinstance(f, (models.BinaryField, models.TextField))
+ if not (f.is_relation and f.auto_created) and not isinstance(f, (BinaryField, TextField))
]
def test_annotate(self):
@@ -66,7 +68,7 @@ class CaseExpressionTests(TestCase):
When(integer=1, then=Value('one')),
When(integer=2, then=Value('two')),
default=Value('other'),
- output_field=models.CharField(),
+ output_field=CharField(),
)).order_by('pk'),
[(1, 'one'), (2, 'two'), (3, 'other'), (2, 'two'), (3, 'other'), (3, 'other'), (4, 'other')],
transform=attrgetter('integer', 'test')
@@ -77,7 +79,7 @@ class CaseExpressionTests(TestCase):
CaseTestModel.objects.annotate(test=Case(
When(integer=1, then=1),
When(integer=2, then=2),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)).order_by('pk'),
[(1, 1), (2, 2), (3, None), (2, 2), (3, None), (3, None), (4, None)],
transform=attrgetter('integer', 'test')
@@ -99,7 +101,7 @@ class CaseExpressionTests(TestCase):
CaseTestModel.objects.annotate(f_test=Case(
When(integer2=F('integer'), then=Value('equal')),
When(integer2=F('integer') + 1, then=Value('+1')),
- output_field=models.CharField(),
+ output_field=CharField(),
)).order_by('pk'),
[(1, 'equal'), (2, '+1'), (3, '+1'), (2, 'equal'), (3, '+1'), (3, 'equal'), (4, '+1')],
transform=attrgetter('integer', 'f_test')
@@ -133,7 +135,7 @@ class CaseExpressionTests(TestCase):
When(integer2=F('o2o_rel__integer'), then=Value('equal')),
When(integer2=F('o2o_rel__integer') + 1, then=Value('+1')),
default=Value('other'),
- output_field=models.CharField(),
+ output_field=CharField(),
)).order_by('pk'),
[(1, 'equal'), (2, '+1'), (3, '+1'), (2, 'equal'), (3, '+1'), (3, 'equal'), (4, 'other')],
transform=attrgetter('integer', 'join_test')
@@ -146,7 +148,7 @@ class CaseExpressionTests(TestCase):
When(o2o_rel__integer=2, then=Value('two')),
When(o2o_rel__integer=3, then=Value('three')),
default=Value('other'),
- output_field=models.CharField(),
+ output_field=CharField(),
)).order_by('pk'),
[(1, 'one'), (2, 'two'), (3, 'three'), (2, 'two'), (3, 'three'), (3, 'three'), (4, 'one')],
transform=attrgetter('integer', 'join_test')
@@ -176,7 +178,7 @@ class CaseExpressionTests(TestCase):
f_test=Case(
When(integer2=F('integer'), then=Value('equal')),
When(integer2=F('f_plus_1'), then=Value('+1')),
- output_field=models.CharField(),
+ output_field=CharField(),
),
).order_by('pk'),
[(1, 'equal'), (2, '+1'), (3, '+1'), (2, 'equal'), (3, '+1'), (3, 'equal'), (4, '+1')],
@@ -193,7 +195,7 @@ class CaseExpressionTests(TestCase):
When(f_minus_2=0, then=Value('zero')),
When(f_minus_2=1, then=Value('one')),
default=Value('other'),
- output_field=models.CharField(),
+ output_field=CharField(),
),
).order_by('pk'),
[(1, 'negative one'), (2, 'zero'), (3, 'one'), (2, 'zero'), (3, 'one'), (3, 'one'), (4, 'other')],
@@ -224,7 +226,7 @@ class CaseExpressionTests(TestCase):
test=Case(
When(integer2=F('min'), then=Value('min')),
When(integer2=F('max'), then=Value('max')),
- output_field=models.CharField(),
+ output_field=CharField(),
),
).order_by('pk'),
[(1, 1, 'min'), (2, 3, 'max'), (3, 4, 'max'), (2, 2, 'min'), (3, 4, 'max'), (3, 3, 'min'), (4, 5, 'min')],
@@ -240,7 +242,7 @@ class CaseExpressionTests(TestCase):
When(max=3, then=Value('max = 3')),
When(max=4, then=Value('max = 4')),
default=Value(''),
- output_field=models.CharField(),
+ output_field=CharField(),
),
).order_by('pk'),
[(1, 1, ''), (2, 3, 'max = 3'), (3, 4, 'max = 4'), (2, 3, 'max = 3'),
@@ -254,7 +256,7 @@ class CaseExpressionTests(TestCase):
When(integer=1, then=Value('one')),
When(integer=2, then=Value('two')),
default=Value('other'),
- output_field=models.CharField(),
+ output_field=CharField(),
)).exclude(test='other').order_by('pk'),
[(1, 'one'), (2, 'two'), (2, 'two')],
transform=attrgetter('integer', 'test')
@@ -267,7 +269,7 @@ class CaseExpressionTests(TestCase):
When(integer=2, then=Value('two')),
When(integer=3, then=Value('three')),
default=Value('other'),
- output_field=models.CharField(),
+ output_field=CharField(),
)).order_by('test').values_list('integer', flat=True)),
[1, 4, 3, 3, 3, 2, 2]
)
@@ -276,7 +278,7 @@ class CaseExpressionTests(TestCase):
objects = CaseTestModel.objects.annotate(
selected=Case(
When(pk__in=[], then=Value('selected')),
- default=Value('not selected'), output_field=models.CharField()
+ default=Value('not selected'), output_field=CharField()
)
)
self.assertEqual(len(objects), CaseTestModel.objects.count())
@@ -289,7 +291,7 @@ class CaseExpressionTests(TestCase):
When(integer=1, then=2),
When(integer=2, then=1),
default=3,
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
) + 1,
).order_by('pk'),
[(1, 3), (2, 2), (3, 4), (2, 2), (3, 4), (3, 4), (4, 4)],
@@ -303,7 +305,7 @@ class CaseExpressionTests(TestCase):
test=Case(
When(integer=F('integer2'), then='pk'),
When(integer=4, then='pk'),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
),
).values('test')).order_by('pk'),
[(1, 1), (2, 2), (3, 3), (4, 5)],
@@ -314,7 +316,7 @@ class CaseExpressionTests(TestCase):
SOME_CASE = Case(
When(pk=0, then=Value('0')),
default=Value('1'),
- output_field=models.CharField(),
+ output_field=CharField(),
)
self.assertQuerysetEqual(
CaseTestModel.objects.annotate(somecase=SOME_CASE).order_by('pk'),
@@ -325,21 +327,21 @@ class CaseExpressionTests(TestCase):
def test_aggregate(self):
self.assertEqual(
CaseTestModel.objects.aggregate(
- one=models.Sum(Case(
+ one=Sum(Case(
When(integer=1, then=1),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)),
- two=models.Sum(Case(
+ two=Sum(Case(
When(integer=2, then=1),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)),
- three=models.Sum(Case(
+ three=Sum(Case(
When(integer=3, then=1),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)),
- four=models.Sum(Case(
+ four=Sum(Case(
When(integer=4, then=1),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)),
),
{'one': 1, 'two': 2, 'three': 3, 'four': 1}
@@ -348,9 +350,9 @@ class CaseExpressionTests(TestCase):
def test_aggregate_with_expression_as_value(self):
self.assertEqual(
CaseTestModel.objects.aggregate(
- one=models.Sum(Case(When(integer=1, then='integer'))),
- two=models.Sum(Case(When(integer=2, then=F('integer') - 1))),
- three=models.Sum(Case(When(integer=3, then=F('integer') + 1))),
+ one=Sum(Case(When(integer=1, then='integer'))),
+ two=Sum(Case(When(integer=2, then=F('integer') - 1))),
+ three=Sum(Case(When(integer=3, then=F('integer') + 1))),
),
{'one': 1, 'two': 2, 'three': 12}
)
@@ -358,13 +360,13 @@ class CaseExpressionTests(TestCase):
def test_aggregate_with_expression_as_condition(self):
self.assertEqual(
CaseTestModel.objects.aggregate(
- equal=models.Sum(Case(
+ equal=Sum(Case(
When(integer2=F('integer'), then=1),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)),
- plus_one=models.Sum(Case(
+ plus_one=Sum(Case(
When(integer2=F('integer') + 1, then=1),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)),
),
{'equal': 3, 'plus_one': 4}
@@ -376,7 +378,7 @@ class CaseExpressionTests(TestCase):
When(integer=2, then=3),
When(integer=3, then=4),
default=1,
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)).order_by('pk'),
[(1, 1), (2, 3), (3, 4), (3, 4)],
transform=attrgetter('integer', 'integer2')
@@ -387,7 +389,7 @@ class CaseExpressionTests(TestCase):
CaseTestModel.objects.filter(integer2=Case(
When(integer=2, then=3),
When(integer=3, then=4),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)).order_by('pk'),
[(2, 3), (3, 4), (3, 4)],
transform=attrgetter('integer', 'integer2')
@@ -409,7 +411,7 @@ class CaseExpressionTests(TestCase):
CaseTestModel.objects.filter(string=Case(
When(integer2=F('integer'), then=Value('2')),
When(integer2=F('integer') + 1, then=Value('3')),
- output_field=models.CharField(),
+ output_field=CharField(),
)).order_by('pk'),
[(3, 4, '3'), (2, 2, '2'), (3, 4, '3')],
transform=attrgetter('integer', 'integer2', 'string')
@@ -431,7 +433,7 @@ class CaseExpressionTests(TestCase):
CaseTestModel.objects.filter(integer=Case(
When(integer2=F('o2o_rel__integer') + 1, then=2),
When(integer2=F('o2o_rel__integer'), then=3),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)).order_by('pk'),
[(2, 3), (3, 3)],
transform=attrgetter('integer', 'integer2')
@@ -443,7 +445,7 @@ class CaseExpressionTests(TestCase):
When(o2o_rel__integer=1, then=1),
When(o2o_rel__integer=2, then=3),
When(o2o_rel__integer=3, then=4),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)).order_by('pk'),
[(1, 1), (2, 3), (3, 4), (3, 4)],
transform=attrgetter('integer', 'integer2')
@@ -472,7 +474,7 @@ class CaseExpressionTests(TestCase):
integer=Case(
When(integer2=F('integer'), then=2),
When(integer2=F('f_plus_1'), then=3),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
),
).order_by('pk'),
[(3, 4), (2, 2), (3, 4)],
@@ -488,7 +490,7 @@ class CaseExpressionTests(TestCase):
When(f_plus_1=3, then=3),
When(f_plus_1=4, then=4),
default=1,
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
),
).order_by('pk'),
[(1, 1), (2, 3), (3, 4), (3, 4)],
@@ -599,7 +601,7 @@ class CaseExpressionTests(TestCase):
integer=Case(
When(integer2=F('o2o_rel__integer') + 1, then=2),
When(integer2=F('o2o_rel__integer'), then=3),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
),
)
@@ -611,7 +613,7 @@ class CaseExpressionTests(TestCase):
When(o2o_rel__integer=2, then=Value('two')),
When(o2o_rel__integer=3, then=Value('three')),
default=Value('other'),
- output_field=models.CharField(),
+ output_field=CharField(),
),
)
@@ -631,9 +633,9 @@ class CaseExpressionTests(TestCase):
def test_update_binary(self):
CaseTestModel.objects.update(
binary=Case(
- When(integer=1, then=Value(b'one', output_field=models.BinaryField())),
- When(integer=2, then=Value(b'two', output_field=models.BinaryField())),
- default=Value(b'', output_field=models.BinaryField()),
+ When(integer=1, then=Value(b'one', output_field=BinaryField())),
+ When(integer=2, then=Value(b'two', output_field=BinaryField())),
+ default=Value(b'', output_field=BinaryField()),
),
)
self.assertQuerysetEqual(
@@ -714,8 +716,8 @@ class CaseExpressionTests(TestCase):
duration=Case(
# fails on sqlite if output_field is not set explicitly on all
# Values containing timedeltas
- When(integer=1, then=Value(timedelta(1), output_field=models.DurationField())),
- When(integer=2, then=Value(timedelta(2), output_field=models.DurationField())),
+ When(integer=1, then=Value(timedelta(1), output_field=DurationField())),
+ When(integer=2, then=Value(timedelta(2), output_field=DurationField())),
),
)
self.assertQuerysetEqual(
@@ -798,7 +800,7 @@ class CaseExpressionTests(TestCase):
# fails on postgresql if output_field is not set explicitly
When(integer=1, then=Value('1.1.1.1')),
When(integer=2, then=Value('2.2.2.2')),
- output_field=models.GenericIPAddressField(),
+ output_field=GenericIPAddressField(),
),
)
self.assertQuerysetEqual(
@@ -902,8 +904,8 @@ class CaseExpressionTests(TestCase):
def test_update_string(self):
CaseTestModel.objects.filter(string__in=['1', '2']).update(
string=Case(
- When(integer=1, then=Value('1', output_field=models.CharField())),
- When(integer=2, then=Value('2', output_field=models.CharField())),
+ When(integer=1, then=Value('1', output_field=CharField())),
+ When(integer=2, then=Value('2', output_field=CharField())),
),
)
self.assertQuerysetEqual(
@@ -931,8 +933,8 @@ class CaseExpressionTests(TestCase):
time=Case(
# fails on sqlite if output_field is not set explicitly on all
# Values containing times
- When(integer=1, then=Value(time(1), output_field=models.TimeField())),
- When(integer=2, then=Value(time(2), output_field=models.TimeField())),
+ When(integer=1, then=Value(time(1), output_field=TimeField())),
+ When(integer=2, then=Value(time(2), output_field=TimeField())),
),
)
self.assertQuerysetEqual(
@@ -965,11 +967,11 @@ class CaseExpressionTests(TestCase):
# Values containing UUIDs
When(integer=1, then=Value(
UUID('11111111111111111111111111111111'),
- output_field=models.UUIDField(),
+ output_field=UUIDField(),
)),
When(integer=2, then=Value(
UUID('22222222222222222222222222222222'),
- output_field=models.UUIDField(),
+ output_field=UUIDField(),
)),
),
)
@@ -1009,7 +1011,7 @@ class CaseExpressionTests(TestCase):
When(integer__lt=2, then=Value('less than 2')),
When(integer__gt=2, then=Value('greater than 2')),
default=Value('equal to 2'),
- output_field=models.CharField(),
+ output_field=CharField(),
),
).order_by('pk'),
[
@@ -1025,7 +1027,7 @@ class CaseExpressionTests(TestCase):
test=Case(
When(integer=2, integer2=3, then=Value('when')),
default=Value('default'),
- output_field=models.CharField(),
+ output_field=CharField(),
),
).order_by('pk'),
[
@@ -1041,7 +1043,7 @@ class CaseExpressionTests(TestCase):
test=Case(
When(Q(integer=2) | Q(integer2=3), then=Value('when')),
default=Value('default'),
- output_field=models.CharField(),
+ output_field=CharField(),
),
).order_by('pk'),
[
@@ -1057,7 +1059,7 @@ class CaseExpressionTests(TestCase):
When(integer=1, then=2),
When(integer=2, then=1),
default=3,
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)).order_by('test', 'pk'),
[(2, 1), (2, 1), (1, 2)],
transform=attrgetter('integer', 'test')
@@ -1069,7 +1071,7 @@ class CaseExpressionTests(TestCase):
When(integer=1, then=2),
When(integer=2, then=1),
default=3,
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)).order_by(F('test').asc(), 'pk'),
[(2, 1), (2, 1), (1, 2)],
transform=attrgetter('integer', 'test')
@@ -1088,7 +1090,7 @@ class CaseExpressionTests(TestCase):
foo=Case(
When(fk_rel__pk=1, then=2),
default=3,
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
),
[(o, 3)],
@@ -1100,7 +1102,7 @@ class CaseExpressionTests(TestCase):
foo=Case(
When(fk_rel__isnull=True, then=2),
default=3,
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
),
[(o, 2)],
@@ -1120,12 +1122,12 @@ class CaseExpressionTests(TestCase):
foo=Case(
When(fk_rel__pk=1, then=2),
default=3,
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
bar=Case(
When(fk_rel__pk=1, then=4),
default=5,
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
),
[(o, 3, 5)],
@@ -1137,12 +1139,12 @@ class CaseExpressionTests(TestCase):
foo=Case(
When(fk_rel__isnull=True, then=2),
default=3,
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
bar=Case(
When(fk_rel__isnull=True, then=4),
default=5,
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
),
[(o, 2, 4)],
@@ -1152,9 +1154,9 @@ class CaseExpressionTests(TestCase):
def test_m2m_exclude(self):
CaseTestModel.objects.create(integer=10, integer2=1, string='1')
qs = CaseTestModel.objects.values_list('id', 'integer').annotate(
- cnt=models.Sum(
+ cnt=Sum(
Case(When(~Q(fk_rel__integer=1), then=1), default=2),
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
).order_by('integer')
# The first o has 2 as its fk_rel__integer=1, thus it hits the
@@ -1174,14 +1176,14 @@ class CaseExpressionTests(TestCase):
# Need to use values before annotate so that Oracle will not group
# by fields it isn't capable of grouping by.
qs = CaseTestModel.objects.values_list('id', 'integer').annotate(
- cnt=models.Sum(
+ cnt=Sum(
Case(When(~Q(fk_rel__integer=1), then=1), default=2),
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
).annotate(
- cnt2=models.Sum(
+ cnt2=Sum(
Case(When(~Q(fk_rel__integer=1), then=1), default=2),
- output_field=models.IntegerField()
+ output_field=IntegerField()
),
).order_by('integer')
self.assertEqual(str(qs.query).count(' JOIN '), 1)
@@ -1218,7 +1220,7 @@ class CaseDocumentationExamples(TestCase):
When(account_type=Client.GOLD, then=Value('5%')),
When(account_type=Client.PLATINUM, then=Value('10%')),
default=Value('0%'),
- output_field=models.CharField(),
+ output_field=CharField(),
),
).order_by('pk'),
[('Jane Doe', '0%'), ('James Smith', '5%'), ('Jack Black', '10%')],
@@ -1234,7 +1236,7 @@ class CaseDocumentationExamples(TestCase):
When(registered_on__lte=a_year_ago, then=Value('10%')),
When(registered_on__lte=a_month_ago, then=Value('5%')),
default=Value('0%'),
- output_field=models.CharField(),
+ output_field=CharField(),
),
).order_by('pk'),
[('Jane Doe', '5%'), ('James Smith', '0%'), ('Jack Black', '10%')],
@@ -1275,26 +1277,26 @@ class CaseDocumentationExamples(TestCase):
)
self.assertEqual(
Client.objects.aggregate(
- regular=models.Count('pk', filter=Q(account_type=Client.REGULAR)),
- gold=models.Count('pk', filter=Q(account_type=Client.GOLD)),
- platinum=models.Count('pk', filter=Q(account_type=Client.PLATINUM)),
+ regular=Count('pk', filter=Q(account_type=Client.REGULAR)),
+ gold=Count('pk', filter=Q(account_type=Client.GOLD)),
+ platinum=Count('pk', filter=Q(account_type=Client.PLATINUM)),
),
{'regular': 2, 'gold': 1, 'platinum': 3}
)
# This was the example before the filter argument was added.
self.assertEqual(
Client.objects.aggregate(
- regular=models.Sum(Case(
+ regular=Sum(Case(
When(account_type=Client.REGULAR, then=1),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)),
- gold=models.Sum(Case(
+ gold=Sum(Case(
When(account_type=Client.GOLD, then=1),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)),
- platinum=models.Sum(Case(
+ platinum=Sum(Case(
When(account_type=Client.PLATINUM, then=1),
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)),
),
{'regular': 2, 'gold': 1, 'platinum': 3}
@@ -1318,12 +1320,12 @@ class CaseDocumentationExamples(TestCase):
expression_1 = Case(
When(account_type__in=[Client.REGULAR, Client.GOLD], then=1),
default=2,
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)
expression_2 = Case(
When(account_type__in=(Client.REGULAR, Client.GOLD), then=1),
default=2,
- output_field=models.IntegerField(),
+ output_field=IntegerField(),
)
expression_3 = Case(When(account_type__in=[Client.REGULAR, Client.GOLD], then=1), default=2)
expression_4 = Case(When(account_type__in=[Client.PLATINUM, Client.GOLD], then=2), default=1)
@@ -1347,7 +1349,7 @@ class CaseWhenTests(SimpleTestCase):
with self.assertRaisesMessage(TypeError, msg):
When(condition=object())
with self.assertRaisesMessage(TypeError, msg):
- When(condition=Value(1, output_field=models.IntegerField()))
+ When(condition=Value(1, output_field=IntegerField()))
with self.assertRaisesMessage(TypeError, msg):
When()
diff --git a/tests/expressions_window/tests.py b/tests/expressions_window/tests.py
index 686594584f..30ed64f529 100644
--- a/tests/expressions_window/tests.py
+++ b/tests/expressions_window/tests.py
@@ -4,10 +4,9 @@ from unittest import mock, skipIf
from django.core.exceptions import FieldError
from django.db import NotSupportedError, connection
from django.db.models import (
- BooleanField, Case, F, Func, OuterRef, Q, RowRange, Subquery, Value,
- ValueRange, When, Window, WindowFrame,
+ Avg, BooleanField, Case, F, Func, Max, Min, OuterRef, Q, RowRange,
+ Subquery, Sum, Value, ValueRange, When, Window, WindowFrame,
)
-from django.db.models.aggregates import Avg, Max, Min, Sum
from django.db.models.functions import (
CumeDist, DenseRank, ExtractYear, FirstValue, Lag, LastValue, Lead,
NthValue, Ntile, PercentRank, Rank, RowNumber, Upper,
diff --git a/tests/foreign_object/models/customers.py b/tests/foreign_object/models/customers.py
index 24c080f407..7e1a3ac370 100644
--- a/tests/foreign_object/models/customers.py
+++ b/tests/foreign_object/models/customers.py
@@ -1,5 +1,4 @@
from django.db import models
-from django.db.models.fields.related import ForeignObject
class Address(models.Model):
@@ -15,7 +14,7 @@ class Address(models.Model):
class Customer(models.Model):
company = models.CharField(max_length=1)
customer_id = models.IntegerField()
- address = ForeignObject(
+ address = models.ForeignObject(
Address, models.CASCADE, null=True,
# order mismatches the Contact ForeignObject.
from_fields=['company', 'customer_id'],
@@ -31,7 +30,7 @@ class Customer(models.Model):
class Contact(models.Model):
company_code = models.CharField(max_length=1)
customer_code = models.IntegerField()
- customer = ForeignObject(
+ customer = models.ForeignObject(
Customer, models.CASCADE, related_name='contacts',
to_fields=['customer_id', 'company'],
from_fields=['customer_code', 'company_code'],
diff --git a/tests/foreign_object/models/empty_join.py b/tests/foreign_object/models/empty_join.py
index 08d1edb18a..8ccecc55cb 100644
--- a/tests/foreign_object/models/empty_join.py
+++ b/tests/foreign_object/models/empty_join.py
@@ -1,12 +1,10 @@
from django.db import models
-from django.db.models.fields.related import (
- ForeignObjectRel, ReverseManyToOneDescriptor,
-)
+from django.db.models.fields.related import ReverseManyToOneDescriptor
from django.db.models.lookups import StartsWith
from django.db.models.query_utils import PathInfo
-class CustomForeignObjectRel(ForeignObjectRel):
+class CustomForeignObjectRel(models.ForeignObjectRel):
"""
Define some extra Field methods so this Rel acts more like a Field, which
lets us use ReverseManyToOneDescriptor in both directions.
diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py
index 7fed5557eb..b211c6e328 100644
--- a/tests/foreign_object/tests.py
+++ b/tests/foreign_object/tests.py
@@ -3,7 +3,6 @@ from operator import attrgetter
from django.core.exceptions import FieldError
from django.db import models
-from django.db.models.fields.related import ForeignObject
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from django.test.utils import isolate_apps
from django.utils import translation
@@ -436,7 +435,7 @@ class TestModelCheckTests(SimpleTestCase):
a = models.PositiveIntegerField()
b = models.PositiveIntegerField()
value = models.CharField(max_length=255)
- parent = ForeignObject(
+ parent = models.ForeignObject(
Parent,
on_delete=models.SET_NULL,
from_fields=('a', 'b'),
@@ -461,7 +460,7 @@ class TestModelCheckTests(SimpleTestCase):
b = models.PositiveIntegerField()
c = models.PositiveIntegerField()
d = models.CharField(max_length=255)
- parent = ForeignObject(
+ parent = models.ForeignObject(
Parent,
on_delete=models.SET_NULL,
from_fields=('a', 'b', 'c'),
diff --git a/tests/generic_relations_regress/models.py b/tests/generic_relations_regress/models.py
index 06f5888fbe..4d5620b877 100644
--- a/tests/generic_relations_regress/models.py
+++ b/tests/generic_relations_regress/models.py
@@ -3,7 +3,6 @@ from django.contrib.contenttypes.fields import (
)
from django.contrib.contenttypes.models import ContentType
from django.db import models
-from django.db.models.deletion import ProtectedError
__all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address',
'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2',
@@ -214,7 +213,7 @@ class Related(models.Model):
def prevent_deletes(sender, instance, **kwargs):
- raise ProtectedError("Not allowed to delete.", [instance])
+ raise models.ProtectedError("Not allowed to delete.", [instance])
models.signals.pre_delete.connect(prevent_deletes, sender=Node)
diff --git a/tests/generic_relations_regress/tests.py b/tests/generic_relations_regress/tests.py
index fc7447fa51..0c62283f01 100644
--- a/tests/generic_relations_regress/tests.py
+++ b/tests/generic_relations_regress/tests.py
@@ -1,6 +1,5 @@
-from django.db.models import Q, Sum
-from django.db.models.deletion import ProtectedError
-from django.db.utils import IntegrityError
+from django.db import IntegrityError
+from django.db.models import ProtectedError, Q, Sum
from django.forms.models import modelform_factory
from django.test import TestCase, skipIfDBFeature
diff --git a/tests/gis_tests/test_fields.py b/tests/gis_tests/test_fields.py
index 5ccaf2df68..c9e6833767 100644
--- a/tests/gis_tests/test_fields.py
+++ b/tests/gis_tests/test_fields.py
@@ -1,6 +1,6 @@
import copy
-from django.contrib.gis.db.models.fields import GeometryField
+from django.contrib.gis.db.models import GeometryField
from django.contrib.gis.db.models.sql import AreaField, DistanceField
from django.test import SimpleTestCase
diff --git a/tests/gis_tests/test_gis_tests_utils.py b/tests/gis_tests/test_gis_tests_utils.py
index 32d072fd9b..96eea8a9c2 100644
--- a/tests/gis_tests/test_gis_tests_utils.py
+++ b/tests/gis_tests/test_gis_tests_utils.py
@@ -1,5 +1,4 @@
from django.db import connection, models
-from django.db.models.expressions import Func
from django.test import SimpleTestCase
from .utils import FuncTestMixin
@@ -8,7 +7,7 @@ from .utils import FuncTestMixin
def test_mutation(raises=True):
def wrapper(mutation_func):
def test(test_case_instance, *args, **kwargs):
- class TestFunc(Func):
+ class TestFunc(models.Func):
output_field = models.IntegerField()
def __init__(self):
diff --git a/tests/gis_tests/utils.py b/tests/gis_tests/utils.py
index 23a99eb66c..d9f81e3c5d 100644
--- a/tests/gis_tests/utils.py
+++ b/tests/gis_tests/utils.py
@@ -5,7 +5,7 @@ from unittest import mock
from django.conf import settings
from django.db import DEFAULT_DB_ALIAS, connection
-from django.db.models.expressions import Func
+from django.db.models import Func
def skipUnlessGISLookup(*gis_lookups):
diff --git a/tests/indexes/tests.py b/tests/indexes/tests.py
index 04ab036139..5ef2835f4e 100644
--- a/tests/indexes/tests.py
+++ b/tests/indexes/tests.py
@@ -2,10 +2,7 @@ import datetime
from unittest import skipIf, skipUnless
from django.db import connection
-from django.db.models import Index
-from django.db.models.deletion import CASCADE
-from django.db.models.fields.related import ForeignKey
-from django.db.models.query_utils import Q
+from django.db.models import CASCADE, ForeignKey, Index, Q
from django.test import (
TestCase, TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature,
)
diff --git a/tests/introspection/tests.py b/tests/introspection/tests.py
index 5e6fd3d741..bafd620232 100644
--- a/tests/introspection/tests.py
+++ b/tests/introspection/tests.py
@@ -1,8 +1,7 @@
from unittest import mock, skipUnless
-from django.db import connection
+from django.db import DatabaseError, connection
from django.db.models import Index
-from django.db.utils import DatabaseError
from django.test import TransactionTestCase, skipUnlessDBFeature
from .models import (
diff --git a/tests/invalid_models_tests/test_relative_fields.py b/tests/invalid_models_tests/test_relative_fields.py
index 786573672f..4211973cf3 100644
--- a/tests/invalid_models_tests/test_relative_fields.py
+++ b/tests/invalid_models_tests/test_relative_fields.py
@@ -2,7 +2,6 @@ from unittest import mock
from django.core.checks import Error, Warning as DjangoWarning
from django.db import connection, models
-from django.db.models.fields.related import ForeignObject
from django.test.testcases import SimpleTestCase
from django.test.utils import isolate_apps, override_settings
@@ -608,7 +607,7 @@ class RelativeFieldTests(SimpleTestCase):
class Child(models.Model):
a = models.PositiveIntegerField()
b = models.PositiveIntegerField()
- parent = ForeignObject(
+ parent = models.ForeignObject(
Parent,
on_delete=models.SET_NULL,
from_fields=('a', 'b'),
@@ -633,7 +632,7 @@ class RelativeFieldTests(SimpleTestCase):
class Child(models.Model):
a = models.PositiveIntegerField()
b = models.PositiveIntegerField()
- parent = ForeignObject(
+ parent = models.ForeignObject(
'invalid_models_tests.Parent',
on_delete=models.SET_NULL,
from_fields=('a', 'b'),
@@ -1441,7 +1440,7 @@ class M2mThroughFieldsTests(SimpleTestCase):
a = models.PositiveIntegerField()
b = models.PositiveIntegerField()
value = models.CharField(max_length=255)
- parent = ForeignObject(
+ parent = models.ForeignObject(
Parent,
on_delete=models.SET_NULL,
from_fields=('a', 'b'),
@@ -1477,7 +1476,7 @@ class M2mThroughFieldsTests(SimpleTestCase):
b = models.PositiveIntegerField()
d = models.PositiveIntegerField()
value = models.CharField(max_length=255)
- parent = ForeignObject(
+ parent = models.ForeignObject(
Parent,
on_delete=models.SET_NULL,
from_fields=('a', 'b', 'd'),
diff --git a/tests/lookup/test_decimalfield.py b/tests/lookup/test_decimalfield.py
index c6d17bce84..5d75b8336d 100644
--- a/tests/lookup/test_decimalfield.py
+++ b/tests/lookup/test_decimalfield.py
@@ -1,5 +1,4 @@
-from django.db.models.aggregates import Sum
-from django.db.models.expressions import F
+from django.db.models import F, Sum
from django.test import TestCase
from .models import Product, Stock
diff --git a/tests/lookup/test_lookups.py b/tests/lookup/test_lookups.py
index 9b2d90fdd9..c3aa48ddad 100644
--- a/tests/lookup/test_lookups.py
+++ b/tests/lookup/test_lookups.py
@@ -1,7 +1,6 @@
from datetime import datetime
-from django.db.models import Value
-from django.db.models.fields import DateTimeField
+from django.db.models import DateTimeField, Value
from django.db.models.lookups import YearLookup
from django.test import SimpleTestCase
diff --git a/tests/lookup/tests.py b/tests/lookup/tests.py
index e6334fece1..baefdf9701 100644
--- a/tests/lookup/tests.py
+++ b/tests/lookup/tests.py
@@ -5,8 +5,7 @@ from operator import attrgetter
from django.core.exceptions import FieldError
from django.db import connection
-from django.db.models import Max
-from django.db.models.expressions import Exists, OuterRef
+from django.db.models import Exists, Max, OuterRef
from django.db.models.functions import Substr
from django.test import TestCase, skipUnlessDBFeature
from django.utils.deprecation import RemovedInDjango40Warning
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py
index a926574b15..d769b206b9 100644
--- a/tests/many_to_one/tests.py
+++ b/tests/many_to_one/tests.py
@@ -2,8 +2,7 @@ import datetime
from copy import deepcopy
from django.core.exceptions import FieldError, MultipleObjectsReturned
-from django.db import models, transaction
-from django.db.utils import IntegrityError
+from django.db import IntegrityError, models, transaction
from django.test import TestCase
from django.utils.translation import gettext_lazy
diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py
index ddba8d12e8..38391cdccf 100644
--- a/tests/migrations/test_executor.py
+++ b/tests/migrations/test_executor.py
@@ -1,12 +1,11 @@
from unittest import mock
from django.apps.registry import apps as global_apps
-from django.db import connection
+from django.db import DatabaseError, connection
from django.db.migrations.exceptions import InvalidMigrationPlan
from django.db.migrations.executor import MigrationExecutor
from django.db.migrations.graph import MigrationGraph
from django.db.migrations.recorder import MigrationRecorder
-from django.db.utils import DatabaseError
from django.test import (
SimpleTestCase, modify_settings, override_settings, skipUnlessDBFeature,
)
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 02971d7a9f..2fb633d41e 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -1,12 +1,12 @@
from django.core.exceptions import FieldDoesNotExist
-from django.db import connection, migrations, models, transaction
+from django.db import (
+ IntegrityError, connection, migrations, models, transaction,
+)
from django.db.migrations.migration import Migration
from django.db.migrations.operations import CreateModel
from django.db.migrations.operations.fields import FieldOperation
from django.db.migrations.state import ModelState, ProjectState
-from django.db.models.fields import NOT_PROVIDED
from django.db.transaction import atomic
-from django.db.utils import IntegrityError
from django.test import SimpleTestCase, override_settings, skipUnlessDBFeature
from .models import FoodManager, FoodQuerySet, UnicodeModel
@@ -979,7 +979,7 @@ class OperationTests(OperationTestBase):
f for n, f in new_state.models["test_adflpd", "pony"].fields
if n == "height"
][0]
- self.assertEqual(field.default, NOT_PROVIDED)
+ self.assertEqual(field.default, models.NOT_PROVIDED)
# Test the database alteration
project_state.apps.get_model("test_adflpd", "pony").objects.create(
weight=4,
diff --git a/tests/model_fields/models.py b/tests/model_fields/models.py
index 0fd5910339..a7efe199ab 100644
--- a/tests/model_fields/models.py
+++ b/tests/model_fields/models.py
@@ -8,10 +8,7 @@ from django.contrib.contenttypes.fields import (
from django.contrib.contenttypes.models import ContentType
from django.core.files.storage import FileSystemStorage
from django.db import models
-from django.db.models.fields.files import ImageField, ImageFieldFile
-from django.db.models.fields.related import (
- ForeignKey, ForeignObject, ManyToManyField, OneToOneField,
-)
+from django.db.models.fields.files import ImageFieldFile
from django.utils.translation import gettext_lazy as _
try:
@@ -255,7 +252,7 @@ if Image:
self.was_opened = True
super().open()
- class TestImageField(ImageField):
+ class TestImageField(models.ImageField):
attr_class = TestImageFieldFile
# Set up a temp directory for file storage.
@@ -359,20 +356,20 @@ class AllFieldsModel(models.Model):
url = models.URLField()
uuid = models.UUIDField()
- fo = ForeignObject(
+ fo = models.ForeignObject(
'self',
on_delete=models.CASCADE,
from_fields=['positive_integer'],
to_fields=['id'],
related_name='reverse'
)
- fk = ForeignKey(
+ fk = models.ForeignKey(
'self',
models.CASCADE,
related_name='reverse2'
)
- m2m = ManyToManyField('self')
- oto = OneToOneField('self', models.CASCADE)
+ m2m = models.ManyToManyField('self')
+ oto = models.OneToOneField('self', models.CASCADE)
object_id = models.PositiveIntegerField()
content_type = models.ForeignKey(ContentType, models.CASCADE)
diff --git a/tests/model_fields/test_field_flags.py b/tests/model_fields/test_field_flags.py
index 0e9256207c..cbc066ac58 100644
--- a/tests/model_fields/test_field_flags.py
+++ b/tests/model_fields/test_field_flags.py
@@ -3,15 +3,11 @@ from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.db import models
-from django.db.models.fields.related import (
- ForeignKey, ForeignObject, ForeignObjectRel, ManyToManyField, ManyToOneRel,
- OneToOneField,
-)
from .models import AllFieldsModel
NON_CONCRETE_FIELDS = (
- ForeignObject,
+ models.ForeignObject,
GenericForeignKey,
GenericRelation,
)
@@ -23,32 +19,32 @@ NON_EDITABLE_FIELDS = (
)
RELATION_FIELDS = (
- ForeignKey,
- ForeignObject,
- ManyToManyField,
- OneToOneField,
+ models.ForeignKey,
+ models.ForeignObject,
+ models.ManyToManyField,
+ models.OneToOneField,
GenericForeignKey,
GenericRelation,
)
MANY_TO_MANY_CLASSES = {
- ManyToManyField,
+ models.ManyToManyField,
}
MANY_TO_ONE_CLASSES = {
- ForeignObject,
- ForeignKey,
+ models.ForeignObject,
+ models.ForeignKey,
GenericForeignKey,
}
ONE_TO_MANY_CLASSES = {
- ForeignObjectRel,
- ManyToOneRel,
+ models.ForeignObjectRel,
+ models.ManyToOneRel,
GenericRelation,
}
ONE_TO_ONE_CLASSES = {
- OneToOneField,
+ models.OneToOneField,
}
FLAG_PROPERTIES = (
diff --git a/tests/model_fields/test_filefield.py b/tests/model_fields/test_filefield.py
index 022121b883..d4e70d6041 100644
--- a/tests/model_fields/test_filefield.py
+++ b/tests/model_fields/test_filefield.py
@@ -8,7 +8,7 @@ from pathlib import Path
from django.core.files import File, temp
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import TemporaryUploadedFile
-from django.db.utils import IntegrityError
+from django.db import IntegrityError
from django.test import TestCase, override_settings
from .models import Document
diff --git a/tests/model_fields/test_promises.py b/tests/model_fields/test_promises.py
index b31b679f51..8e7f54b194 100644
--- a/tests/model_fields/test_promises.py
+++ b/tests/model_fields/test_promises.py
@@ -1,14 +1,14 @@
import datetime
from decimal import Decimal
-from django.db.models.fields import (
+from django.db.models import (
AutoField, BinaryField, BooleanField, CharField, DateField, DateTimeField,
- DecimalField, EmailField, FilePathField, FloatField, GenericIPAddressField,
- IntegerField, IPAddressField, NullBooleanField, PositiveBigIntegerField,
- PositiveIntegerField, PositiveSmallIntegerField, SlugField,
- SmallIntegerField, TextField, TimeField, URLField,
+ DecimalField, EmailField, FileField, FilePathField, FloatField,
+ GenericIPAddressField, ImageField, IntegerField, IPAddressField,
+ NullBooleanField, PositiveBigIntegerField, PositiveIntegerField,
+ PositiveSmallIntegerField, SlugField, SmallIntegerField, TextField,
+ TimeField, URLField,
)
-from django.db.models.fields.files import FileField, ImageField
from django.test import SimpleTestCase
from django.utils.functional import lazy
diff --git a/tests/model_indexes/tests.py b/tests/model_indexes/tests.py
index 6a31109031..15ec702937 100644
--- a/tests/model_indexes/tests.py
+++ b/tests/model_indexes/tests.py
@@ -2,7 +2,6 @@ from unittest import mock
from django.conf import settings
from django.db import connection, models
-from django.db.models.query_utils import Q
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from django.test.utils import isolate_apps
@@ -17,7 +16,7 @@ class SimpleIndexesTests(SimpleTestCase):
def test_repr(self):
index = models.Index(fields=['title'])
multi_col_index = models.Index(fields=['title', 'author'])
- partial_index = models.Index(fields=['title'], name='long_books_idx', condition=Q(pages__gt=400))
+ partial_index = models.Index(fields=['title'], name='long_books_idx', condition=models.Q(pages__gt=400))
self.assertEqual(repr(index), "<Index: fields='title'>")
self.assertEqual(repr(multi_col_index), "<Index: fields='title, author'>")
self.assertEqual(repr(partial_index), "<Index: fields='title', condition=(AND: ('pages__gt', 400))>")
@@ -60,7 +59,7 @@ class SimpleIndexesTests(SimpleTestCase):
def test_condition_requires_index_name(self):
with self.assertRaisesMessage(ValueError, 'An index must be named to use condition.'):
- models.Index(condition=Q(pages__gt=400))
+ models.Index(condition=models.Q(pages__gt=400))
def test_condition_must_be_q(self):
with self.assertRaisesMessage(ValueError, 'Index.condition must be a Q instance.'):
@@ -114,7 +113,7 @@ class SimpleIndexesTests(SimpleTestCase):
index = models.Index(
name='big_book_index',
fields=['title'],
- condition=Q(pages__gt=400),
+ condition=models.Q(pages__gt=400),
)
index.set_name_with_model(Book)
path, args, kwargs = index.deconstruct()
@@ -125,7 +124,7 @@ class SimpleIndexesTests(SimpleTestCase):
{
'fields': ['title'],
'name': 'model_index_title_196f42_idx',
- 'condition': Q(pages__gt=400),
+ 'condition': models.Q(pages__gt=400),
}
)
diff --git a/tests/model_meta/tests.py b/tests/model_meta/tests.py
index 0a3049c6dc..ad58b336bd 100644
--- a/tests/model_meta/tests.py
+++ b/tests/model_meta/tests.py
@@ -3,7 +3,9 @@ from django.contrib.contenttypes.fields import (
GenericForeignKey, GenericRelation,
)
from django.core.exceptions import FieldDoesNotExist
-from django.db.models.fields import CharField, Field, related
+from django.db.models import (
+ CharField, Field, ForeignObjectRel, ManyToManyField,
+)
from django.db.models.options import EMPTY_RELATION_TREE, IMMUTABLE_WARNING
from django.test import SimpleTestCase
@@ -175,17 +177,17 @@ class GetFieldByNameTests(OptionsBaseTests):
def test_get_m2m_field(self):
field_info = self._details(Person, Person._meta.get_field('m2m_base'))
self.assertEqual(field_info[1:], (BasePerson, True, True))
- self.assertIsInstance(field_info[0], related.ManyToManyField)
+ self.assertIsInstance(field_info[0], ManyToManyField)
def test_get_related_object(self):
field_info = self._details(Person, Person._meta.get_field('relating_baseperson'))
self.assertEqual(field_info[1:], (BasePerson, False, False))
- self.assertIsInstance(field_info[0], related.ForeignObjectRel)
+ self.assertIsInstance(field_info[0], ForeignObjectRel)
def test_get_related_m2m(self):
field_info = self._details(Person, Person._meta.get_field('relating_people'))
self.assertEqual(field_info[1:], (None, False, True))
- self.assertIsInstance(field_info[0], related.ForeignObjectRel)
+ self.assertIsInstance(field_info[0], ForeignObjectRel)
def test_get_generic_relation(self):
field_info = self._details(Person, Person._meta.get_field('generic_relation_base'))
diff --git a/tests/ordering/models.py b/tests/ordering/models.py
index 62df09351f..f5a237fe45 100644
--- a/tests/ordering/models.py
+++ b/tests/ordering/models.py
@@ -14,7 +14,6 @@ undefined -- not random, just undefined.
"""
from django.db import models
-from django.db.models.expressions import OrderBy
class Author(models.Model):
@@ -35,7 +34,7 @@ class Article(models.Model):
'-pub_date',
models.F('headline'),
models.F('author__name').asc(),
- OrderBy(models.F('second_author__name')),
+ models.OrderBy(models.F('second_author__name')),
)
def __str__(self):
diff --git a/tests/postgres_tests/test_aggregates.py b/tests/postgres_tests/test_aggregates.py
index a1dbe4441c..c97ed8e62d 100644
--- a/tests/postgres_tests/test_aggregates.py
+++ b/tests/postgres_tests/test_aggregates.py
@@ -1,7 +1,6 @@
import json
-from django.db.models import CharField, Q
-from django.db.models.expressions import F, OuterRef, Subquery, Value
+from django.db.models import CharField, F, OuterRef, Q, Subquery, Value
from django.db.models.functions import Cast, Concat, Substr
from django.test.utils import Approximate
diff --git a/tests/postgres_tests/test_constraints.py b/tests/postgres_tests/test_constraints.py
index b22821294a..ccdd7b818d 100644
--- a/tests/postgres_tests/test_constraints.py
+++ b/tests/postgres_tests/test_constraints.py
@@ -1,10 +1,8 @@
import datetime
from unittest import mock
-from django.db import connection, transaction
-from django.db.models import F, Func, Q
-from django.db.models.constraints import CheckConstraint
-from django.db.utils import IntegrityError
+from django.db import IntegrityError, connection, transaction
+from django.db.models import CheckConstraint, F, Func, Q
from django.utils import timezone
from . import PostgreSQLTestCase
diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py
index dbb1357c41..478e0e77ca 100644
--- a/tests/postgres_tests/test_hstore.py
+++ b/tests/postgres_tests/test_hstore.py
@@ -2,7 +2,8 @@ import json
from django.core import checks, exceptions, serializers
from django.db import connection
-from django.db.models.expressions import OuterRef, RawSQL, Subquery
+from django.db.models import OuterRef, Subquery
+from django.db.models.expressions import RawSQL
from django.forms import Form
from django.test.utils import CaptureQueriesContext, isolate_apps
diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py
index 91cac631e2..acdf1f4771 100644
--- a/tests/postgres_tests/test_indexes.py
+++ b/tests/postgres_tests/test_indexes.py
@@ -4,11 +4,9 @@ from django.contrib.postgres.indexes import (
BloomIndex, BrinIndex, BTreeIndex, GinIndex, GistIndex, HashIndex,
SpGistIndex,
)
-from django.db import connection
-from django.db.models import CharField
+from django.db import NotSupportedError, connection
+from django.db.models import CharField, Q
from django.db.models.functions import Length
-from django.db.models.query_utils import Q
-from django.db.utils import NotSupportedError
from django.test import skipUnlessDBFeature
from django.test.utils import register_lookup
diff --git a/tests/postgres_tests/test_operations.py b/tests/postgres_tests/test_operations.py
index 7be6de9eff..95c88d5fe0 100644
--- a/tests/postgres_tests/test_operations.py
+++ b/tests/postgres_tests/test_operations.py
@@ -2,9 +2,8 @@ import unittest
from migrations.test_base import OperationTestBase
-from django.db import connection, models
+from django.db import NotSupportedError, connection
from django.db.models import Index
-from django.db.utils import NotSupportedError
from django.test import modify_settings
try:
@@ -26,7 +25,7 @@ class AddIndexConcurrentlyTests(OperationTestBase):
new_state = project_state.clone()
operation = AddIndexConcurrently(
'Pony',
- models.Index(fields=['pink'], name='pony_pink_idx'),
+ Index(fields=['pink'], name='pony_pink_idx'),
)
msg = (
'The AddIndexConcurrently operation cannot be executed inside '
diff --git a/tests/prefetch_related/models.py b/tests/prefetch_related/models.py
index 5540dfecf1..a3c0237d8e 100644
--- a/tests/prefetch_related/models.py
+++ b/tests/prefetch_related/models.py
@@ -5,7 +5,7 @@ from django.contrib.contenttypes.fields import (
)
from django.contrib.contenttypes.models import ContentType
from django.db import models
-from django.db.models.query import ModelIterable, QuerySet
+from django.db.models.query import ModelIterable
from django.utils.functional import cached_property
@@ -104,7 +104,7 @@ class ModelIterableSubclass(ModelIterable):
pass
-class TeacherQuerySet(QuerySet):
+class TeacherQuerySet(models.QuerySet):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._iterable_class = ModelIterableSubclass
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py
index 226dfb8ab9..c7db0667bb 100644
--- a/tests/prefetch_related/tests.py
+++ b/tests/prefetch_related/tests.py
@@ -3,8 +3,8 @@ from unittest import mock
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.db import connection
-from django.db.models import Prefetch, QuerySet
-from django.db.models.query import get_prefetcher, prefetch_related_objects
+from django.db.models import Prefetch, QuerySet, prefetch_related_objects
+from django.db.models.query import get_prefetcher
from django.db.models.sql import Query
from django.test import TestCase, override_settings
from django.test.utils import CaptureQueriesContext
diff --git a/tests/queries/test_qs_combinators.py b/tests/queries/test_qs_combinators.py
index 71309ecf1b..1d159e1fed 100644
--- a/tests/queries/test_qs_combinators.py
+++ b/tests/queries/test_qs_combinators.py
@@ -1,6 +1,5 @@
-from django.db import connection
+from django.db import DatabaseError, NotSupportedError, connection
from django.db.models import Exists, F, IntegerField, OuterRef, Value
-from django.db.utils import DatabaseError, NotSupportedError
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from .models import Number, ReservedName
diff --git a/tests/schema/fields.py b/tests/schema/fields.py
index 5f3244b767..e4b62eab39 100644
--- a/tests/schema/fields.py
+++ b/tests/schema/fields.py
@@ -2,8 +2,8 @@ from functools import partial
from django.db import models
from django.db.models.fields.related import (
- RECURSIVE_RELATIONSHIP_CONSTANT, ManyToManyDescriptor, ManyToManyField,
- ManyToManyRel, RelatedField, create_many_to_many_intermediary_model,
+ RECURSIVE_RELATIONSHIP_CONSTANT, ManyToManyDescriptor, RelatedField,
+ create_many_to_many_intermediary_model,
)
@@ -20,7 +20,7 @@ class CustomManyToManyField(RelatedField):
to._meta
except AttributeError:
to = str(to)
- kwargs['rel'] = ManyToManyRel(
+ kwargs['rel'] = models.ManyToManyRel(
self, to,
related_name=related_name,
related_query_name=related_query_name,
@@ -50,13 +50,13 @@ class CustomManyToManyField(RelatedField):
return 'ManyToManyField'
# Copy those methods from ManyToManyField because they don't call super() internally
- contribute_to_related_class = ManyToManyField.__dict__['contribute_to_related_class']
- _get_m2m_attr = ManyToManyField.__dict__['_get_m2m_attr']
- _get_m2m_reverse_attr = ManyToManyField.__dict__['_get_m2m_reverse_attr']
- _get_m2m_db_table = ManyToManyField.__dict__['_get_m2m_db_table']
+ contribute_to_related_class = models.ManyToManyField.__dict__['contribute_to_related_class']
+ _get_m2m_attr = models.ManyToManyField.__dict__['_get_m2m_attr']
+ _get_m2m_reverse_attr = models.ManyToManyField.__dict__['_get_m2m_reverse_attr']
+ _get_m2m_db_table = models.ManyToManyField.__dict__['_get_m2m_db_table']
-class InheritedManyToManyField(ManyToManyField):
+class InheritedManyToManyField(models.ManyToManyField):
pass
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index d8f23606c1..7d16cf3655 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -6,22 +6,16 @@ from unittest import mock
from django.core.management.color import no_style
from django.db import (
- DatabaseError, IntegrityError, OperationalError, connection,
+ DatabaseError, DataError, IntegrityError, OperationalError, connection,
)
-from django.db.models import Index, Model, Q
-from django.db.models.constraints import CheckConstraint, UniqueConstraint
-from django.db.models.deletion import CASCADE, PROTECT
-from django.db.models.fields import (
- AutoField, BigAutoField, BigIntegerField, BinaryField, BooleanField,
- CharField, DateField, DateTimeField, IntegerField, PositiveIntegerField,
- SlugField, SmallAutoField, SmallIntegerField, TextField, TimeField,
- UUIDField,
-)
-from django.db.models.fields.related import (
- ForeignKey, ForeignObject, ManyToManyField, OneToOneField,
+from django.db.models import (
+ CASCADE, PROTECT, AutoField, BigAutoField, BigIntegerField, BinaryField,
+ BooleanField, CharField, CheckConstraint, DateField, DateTimeField,
+ ForeignKey, ForeignObject, Index, IntegerField, ManyToManyField, Model,
+ OneToOneField, PositiveIntegerField, Q, SlugField, SmallAutoField,
+ SmallIntegerField, TextField, TimeField, UniqueConstraint, UUIDField,
)
from django.db.transaction import TransactionManagementError, atomic
-from django.db.utils import DataError
from django.test import (
TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature,
)