summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2015-10-09 21:03:04 -0400
committerTim Graham <timograham@gmail.com>2015-10-10 09:48:50 -0400
commit67732a9b183d2e84c85147b04fdf9499f4395ac6 (patch)
tree86ffa81542c884a7c38f71ff3443732139c65e4b /tests
parent5171f56faeb9ec27153c7e7319c96d3fba774ea5 (diff)
Fixed #24687 -- Added select_related() validation for nested non-relational fields.
The removed test was added in the original select_related() validation patch (45d4e43d2d25b902e3821b612209afa951a8bcb8), but there doesn't seem to be any reason for it. Thanks Claude Paroz for help and review.
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_changelist/admin.py2
-rw-r--r--tests/admin_changelist/tests.py4
-rw-r--r--tests/gis_tests/relatedapp/tests.py3
-rw-r--r--tests/select_related/tests.py10
4 files changed, 9 insertions, 10 deletions
diff --git a/tests/admin_changelist/admin.py b/tests/admin_changelist/admin.py
index c32082f78a..4ca5ae587a 100644
--- a/tests/admin_changelist/admin.py
+++ b/tests/admin_changelist/admin.py
@@ -36,7 +36,7 @@ class ChildAdmin(admin.ModelAdmin):
list_filter = ['parent', 'age']
def get_queryset(self, request):
- return super(ChildAdmin, self).get_queryset(request).select_related("parent__name")
+ return super(ChildAdmin, self).get_queryset(request).select_related("parent")
class CustomPaginationAdmin(ChildAdmin):
diff --git a/tests/admin_changelist/tests.py b/tests/admin_changelist/tests.py
index caf9beeea0..e5a0ae2c2b 100644
--- a/tests/admin_changelist/tests.py
+++ b/tests/admin_changelist/tests.py
@@ -75,9 +75,7 @@ class ChangeListTests(TestCase):
request, Child,
*get_changelist_args(m, list_select_related=m.get_list_select_related(request))
)
- self.assertEqual(cl.queryset.query.select_related, {
- 'parent': {'name': {}}
- })
+ self.assertEqual(cl.queryset.query.select_related, {'parent': {}})
def test_select_related_as_tuple(self):
ia = InvitationAdmin(Invitation, custom_site)
diff --git a/tests/gis_tests/relatedapp/tests.py b/tests/gis_tests/relatedapp/tests.py
index 14828455fb..d6950f7432 100644
--- a/tests/gis_tests/relatedapp/tests.py
+++ b/tests/gis_tests/relatedapp/tests.py
@@ -62,6 +62,9 @@ class RelatedGeoModelTest(TestCase):
qs = list(City.objects.filter(name=name).transform(srid, field_name='location__point'))
check_pnt(GEOSGeometry(wkt, srid), qs[0].location.point)
+ # Relations more than one level deep can be queried.
+ self.assertEqual(list(Parcel.objects.transform(srid, field_name='city__location__point')), [])
+
@skipUnlessDBFeature("supports_extent_aggr")
def test_related_extent_aggregate(self):
"Testing the `Extent` aggregate on related geographic models."
diff --git a/tests/select_related/tests.py b/tests/select_related/tests.py
index b8acd586a6..93d96c9665 100644
--- a/tests/select_related/tests.py
+++ b/tests/select_related/tests.py
@@ -134,12 +134,6 @@ class SelectRelatedTests(TestCase):
orders = [o.genus.family.order.name for o in world]
self.assertEqual(orders, ['Agaricales'])
- def test_single_related_field(self):
- with self.assertNumQueries(1):
- species = Species.objects.select_related('genus__name')
- names = [s.genus.name for s in species]
- self.assertEqual(sorted(names), ['Amanita', 'Drosophila', 'Homo', 'Pisum'])
-
def test_field_traversal(self):
with self.assertNumQueries(1):
s = (Species.objects.all()
@@ -206,6 +200,10 @@ class SelectRelatedValidationTests(SimpleTestCase):
with self.assertRaisesMessage(FieldError, self.non_relational_error % ('name', '(none)')):
list(Domain.objects.select_related('name'))
+ def test_non_relational_field_nested(self):
+ with self.assertRaisesMessage(FieldError, self.non_relational_error % ('name', 'family')):
+ list(Species.objects.select_related('genus__name'))
+
def test_many_to_many_field(self):
with self.assertRaisesMessage(FieldError, self.invalid_error % ('toppings', '(none)')):
list(Pizza.objects.select_related('toppings'))