summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/defer/tests.py4
-rw-r--r--tests/defer_regress/tests.py14
-rw-r--r--tests/gis_tests/relatedapp/tests.py2
-rw-r--r--tests/m2m_intermediary/tests.py2
-rw-r--r--tests/many_to_one/tests.py6
-rw-r--r--tests/model_inheritance_regress/tests.py2
-rw-r--r--tests/null_fk/tests.py4
-rw-r--r--tests/proxy_models/tests.py18
-rw-r--r--tests/queries/tests.py8
-rw-r--r--tests/select_related/tests.py2
-rw-r--r--tests/select_related_regress/tests.py12
11 files changed, 43 insertions, 31 deletions
diff --git a/tests/defer/tests.py b/tests/defer/tests.py
index ea7703c1e3..fd88b1d413 100644
--- a/tests/defer/tests.py
+++ b/tests/defer/tests.py
@@ -129,14 +129,14 @@ class DeferTests(AssertionMixin, TestCase):
self.assert_delayed(qs.only("name").get(pk=self.p1.pk), 2)
def test_defer_with_select_related(self):
- obj = Primary.objects.select_related().defer(
+ obj = Primary.objects.select_related("related").defer(
"related__first", "related__second"
)[0]
self.assert_delayed(obj.related, 2)
self.assert_delayed(obj, 0)
def test_only_with_select_related(self):
- obj = Primary.objects.select_related().only("related__first")[0]
+ obj = Primary.objects.select_related("related").only("related__first")[0]
self.assert_delayed(obj, 2)
self.assert_delayed(obj.related, 1)
self.assertEqual(obj.related_id, self.s1.pk)
diff --git a/tests/defer_regress/tests.py b/tests/defer_regress/tests.py
index 2089c8603f..a54e9a8ea7 100644
--- a/tests/defer_regress/tests.py
+++ b/tests/defer_regress/tests.py
@@ -65,11 +65,13 @@ class DeferRegressionTest(TestCase):
c2 = Child.objects.create(name="c2", value=37)
Leaf.objects.create(name="l1", child=c1, second_child=c2)
- obj = Leaf.objects.only("name", "child").select_related()[0]
+ obj = Leaf.objects.only("name", "child").select_related("child")[0]
self.assertEqual(obj.child.name, "c1")
self.assertQuerySetEqual(
- Leaf.objects.select_related().only("child__name", "second_child__name"),
+ Leaf.objects.select_related("child", "second_child").only(
+ "child__name", "second_child__name"
+ ),
[
"l1",
],
@@ -86,13 +88,15 @@ class DeferRegressionTest(TestCase):
# Regression for #10733 - only() can be used on a model with two
# foreign keys.
- results = Leaf.objects.only("name", "child", "second_child").select_related()
+ results = Leaf.objects.only("name", "child", "second_child").select_related(
+ "child", "second_child"
+ )
self.assertEqual(results[0].child.name, "c1")
self.assertEqual(results[0].second_child.name, "c2")
results = Leaf.objects.only(
"name", "child", "second_child", "child__name", "second_child__name"
- ).select_related()
+ ).select_related("child", "second_child")
self.assertEqual(results[0].child.name, "c1")
self.assertEqual(results[0].second_child.name, "c2")
@@ -213,7 +217,7 @@ class DeferRegressionTest(TestCase):
item = Item.objects.create(name="first", value=47)
RelatedItem.objects.create(item=item)
# Defer fields with only()
- obj = ProxyRelated.objects.select_related().only("item__name")[0]
+ obj = ProxyRelated.objects.select_related("item").only("item__name")[0]
with self.assertNumQueries(0):
self.assertEqual(obj.item.name, "first")
with self.assertNumQueries(1):
diff --git a/tests/gis_tests/relatedapp/tests.py b/tests/gis_tests/relatedapp/tests.py
index 99294f3c50..68d9095269 100644
--- a/tests/gis_tests/relatedapp/tests.py
+++ b/tests/gis_tests/relatedapp/tests.py
@@ -116,7 +116,7 @@ class RelatedGeoModelTest(TestCase):
select_related on a query over a model with an FK to a model subclass.
"""
# Regression test for #9752.
- list(DirectoryEntry.objects.select_related())
+ list(DirectoryEntry.objects.select_related("location"))
@skipUnlessGISLookup("within")
def test06_f_expressions(self):
diff --git a/tests/m2m_intermediary/tests.py b/tests/m2m_intermediary/tests.py
index 93abbde65e..0dcb00fb3a 100644
--- a/tests/m2m_intermediary/tests.py
+++ b/tests/m2m_intermediary/tests.py
@@ -18,7 +18,7 @@ class M2MIntermediaryTests(TestCase):
w2 = Writer.objects.create(reporter=r2, article=a, position="Contributor")
self.assertQuerySetEqual(
- a.writer_set.select_related().order_by("-position"),
+ a.writer_set.select_related("reporter", "article").order_by("-position"),
[
("John Smith", "Main writer"),
("Jane Doe", "Contributor"),
diff --git a/tests/many_to_one/tests.py b/tests/many_to_one/tests.py
index d6149d521f..3e665979ee 100644
--- a/tests/many_to_one/tests.py
+++ b/tests/many_to_one/tests.py
@@ -467,15 +467,15 @@ class ManyToOneTests(TestCase):
headline="Second", pub_date=datetime.date(1980, 4, 23), reporter=r2
)
self.assertEqual(
- list(Article.objects.select_related().dates("pub_date", "day")),
+ list(Article.objects.select_related("reporter").dates("pub_date", "day")),
[datetime.date(1980, 4, 23), datetime.date(2005, 7, 27)],
)
self.assertEqual(
- list(Article.objects.select_related().dates("pub_date", "month")),
+ list(Article.objects.select_related("reporter").dates("pub_date", "month")),
[datetime.date(1980, 4, 1), datetime.date(2005, 7, 1)],
)
self.assertEqual(
- list(Article.objects.select_related().dates("pub_date", "year")),
+ list(Article.objects.select_related("reporter").dates("pub_date", "year")),
[datetime.date(1980, 1, 1), datetime.date(2005, 1, 1)],
)
diff --git a/tests/model_inheritance_regress/tests.py b/tests/model_inheritance_regress/tests.py
index adc2a22fc4..27dff6ae91 100644
--- a/tests/model_inheritance_regress/tests.py
+++ b/tests/model_inheritance_regress/tests.py
@@ -528,7 +528,7 @@ class ModelInheritanceTest(TestCase):
Supplier.objects.create(name="Jane", restaurant=r2)
self.assertQuerySetEqual(
- Supplier.objects.order_by("name").select_related(),
+ Supplier.objects.order_by("name").select_related("restaurant"),
[
"Jane",
"John",
diff --git a/tests/null_fk/tests.py b/tests/null_fk/tests.py
index ac7f7a8289..7abcc5addb 100644
--- a/tests/null_fk/tests.py
+++ b/tests/null_fk/tests.py
@@ -17,9 +17,9 @@ class NullFkTests(TestCase):
# specified set of fields will properly LEFT JOIN multiple levels of
# NULLs (and the things that come after the NULLs, or else data that
# should exist won't). Regression test for #7369.
- c = Comment.objects.select_related().get(id=c1.id)
+ c = Comment.objects.select_related("post").get(id=c1.id)
self.assertEqual(c.post, p)
- self.assertIsNone(Comment.objects.select_related().get(id=c2.id).post)
+ self.assertIsNone(Comment.objects.select_related("post").get(id=c2.id).post)
self.assertQuerySetEqual(
Comment.objects.select_related("post__forum__system_info").all(),
diff --git a/tests/proxy_models/tests.py b/tests/proxy_models/tests.py
index 98bba949f5..e7d4ec714f 100644
--- a/tests/proxy_models/tests.py
+++ b/tests/proxy_models/tests.py
@@ -320,17 +320,17 @@ class ProxyModelTests(TestCase):
country = Country.objects.create(name="Australia")
State.objects.create(name="New South Wales", country=country)
- resp = [s.name for s in State.objects.select_related()]
+ resp = [s.name for s in State.objects.select_related("country")]
self.assertEqual(resp, ["New South Wales"])
- resp = [s.name for s in StateProxy.objects.select_related()]
+ resp = [s.name for s in StateProxy.objects.select_related("country")]
self.assertEqual(resp, ["New South Wales"])
self.assertEqual(
StateProxy.objects.get(name="New South Wales").name, "New South Wales"
)
- resp = StateProxy.objects.select_related().get(name="New South Wales")
+ resp = StateProxy.objects.select_related("country").get(name="New South Wales")
self.assertEqual(resp.name, "New South Wales")
def test_filter_proxy_relation_reverse(self):
@@ -369,15 +369,19 @@ class ProxyModelTests(TestCase):
self.assertEqual(repr(resp), "<ProxyBug: ProxyBug:fix this>")
# Select related + filter on proxy
- resp = ProxyBug.objects.select_related().get(version__icontains="beta")
+ resp = ProxyBug.objects.select_related("reporter").get(
+ version__icontains="beta"
+ )
self.assertEqual(repr(resp), "<ProxyBug: ProxyBug:fix this>")
# Proxy of proxy, select_related + filter
- resp = ProxyProxyBug.objects.select_related().get(version__icontains="beta")
+ resp = ProxyProxyBug.objects.select_related("reporter").get(
+ version__icontains="beta"
+ )
self.assertEqual(repr(resp), "<ProxyProxyBug: ProxyProxyBug:fix this>")
# Select related + filter on a related proxy field
- resp = ProxyImprovement.objects.select_related().get(
+ resp = ProxyImprovement.objects.select_related("reporter").get(
reporter__name__icontains="butor"
)
self.assertEqual(
@@ -385,7 +389,7 @@ class ProxyModelTests(TestCase):
)
# Select related + filter on a related proxy of proxy field
- resp = ProxyImprovement.objects.select_related().get(
+ resp = ProxyImprovement.objects.select_related("associated_bug").get(
associated_bug__summary__icontains="fix"
)
self.assertEqual(
diff --git a/tests/queries/tests.py b/tests/queries/tests.py
index a9f10de7b3..6f90cb033e 100644
--- a/tests/queries/tests.py
+++ b/tests/queries/tests.py
@@ -617,7 +617,7 @@ class Queries1Tests(TestCase):
def test_ticket2496(self):
self.assertSequenceEqual(
Item.objects.extra(tables=["queries_author"])
- .select_related()
+ .select_related("creator")
.order_by("name")[:1],
[self.i4],
)
@@ -668,7 +668,9 @@ class Queries1Tests(TestCase):
self.assertEqual(len(qs.query.alias_map), 1)
def test_tickets_2874_3002(self):
- qs = Item.objects.select_related().order_by("note__note", "name")
+ qs = Item.objects.select_related("creator", "note").order_by(
+ "note__note", "name"
+ )
self.assertQuerySetEqual(qs, [self.i2, self.i4, self.i1, self.i3])
# This is also a good select_related() test because there are multiple
@@ -853,7 +855,7 @@ class Queries1Tests(TestCase):
# We should also be able to pickle things that use select_related().
# The only tricky thing here is to ensure that we do the related
# selections properly after unpickling.
- qs = Item.objects.select_related()
+ qs = Item.objects.select_related("creator", "note")
query = qs.query.get_compiler(qs.db).as_sql()[0]
query2 = pickle.loads(pickle.dumps(qs.query))
self.assertEqual(query2.get_compiler(qs.db).as_sql()[0], query)
diff --git a/tests/select_related/tests.py b/tests/select_related/tests.py
index 59d1270aa0..daea73a5c6 100644
--- a/tests/select_related/tests.py
+++ b/tests/select_related/tests.py
@@ -137,7 +137,7 @@ class SelectRelatedTests(TestCase):
def test_select_related_with_extra(self):
s = (
Species.objects.all()
- .select_related()
+ .select_related("genus")
.extra(select={"a": "select_related_species.id + 10"})[0]
)
self.assertEqual(s.id + 10, s.a)
diff --git a/tests/select_related_regress/tests.py b/tests/select_related_regress/tests.py
index b271c5b48c..8e24098e28 100644
--- a/tests/select_related_regress/tests.py
+++ b/tests/select_related_regress/tests.py
@@ -62,7 +62,7 @@ class SelectRelatedRegressTests(TestCase):
Connection.objects.filter(
start__device__building=b, end__device__building=b
)
- .select_related()
+ .select_related("start__device__building", "end__device__building")
.order_by("id")
)
self.assertEqual(
@@ -93,7 +93,7 @@ class SelectRelatedRegressTests(TestCase):
c = Class.objects.create(org=o)
Enrollment.objects.create(std=s, cls=c)
- e_related = Enrollment.objects.select_related()[0]
+ e_related = Enrollment.objects.select_related("std", "cls")[0]
self.assertEqual(e_related.std.person.user.name, "std")
self.assertEqual(e_related.cls.org.person.user.name, "org")
@@ -112,7 +112,9 @@ class SelectRelatedRegressTests(TestCase):
client = Client.objects.create(name="client", status=active)
self.assertEqual(client.status, active)
- self.assertEqual(Client.objects.select_related()[0].status, active)
+ self.assertEqual(
+ Client.objects.select_related("state", "status")[0].status, active
+ )
self.assertEqual(Client.objects.select_related("state")[0].status, active)
self.assertEqual(
Client.objects.select_related("state", "status")[0].status, active
@@ -221,7 +223,7 @@ class SelectRelatedRegressTests(TestCase):
Chick.objects.create(name="Chick", mother=hen)
self.assertEqual(Chick.objects.all()[0].mother.name, "Hen")
- self.assertEqual(Chick.objects.select_related()[0].mother.name, "Hen")
+ self.assertEqual(Chick.objects.select_related("mother")[0].mother.name, "Hen")
def test_regression_10733(self):
a = A.objects.create(name="a", lots_of_text="lots_of_text_a", a_field="a_field")
@@ -237,7 +239,7 @@ class SelectRelatedRegressTests(TestCase):
"c_b__lots_of_text",
"c_a__name",
"c_b__name",
- ).select_related()
+ ).select_related("c_a", "c_b")
self.assertSequenceEqual(results, [c])
with self.assertNumQueries(0):
qs_c = results[0]