summaryrefslogtreecommitdiff
path: root/tests/model_forms
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_forms')
-rw-r--r--tests/model_forms/test_modelchoicefield.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py
index 6b0f00cf7f..733175823f 100644
--- a/tests/model_forms/test_modelchoicefield.py
+++ b/tests/model_forms/test_modelchoicefield.py
@@ -257,6 +257,17 @@ class ModelChoiceFieldTests(TestCase):
(self.c3.pk, 'Third'),
])
+ def test_queryset_result_cache_is_reused(self):
+ f = forms.ModelChoiceField(Category.objects.all())
+ with self.assertNumQueries(1):
+ # list() calls __len__() and __iter__(); no duplicate queries.
+ self.assertEqual(list(f.choices), [
+ ('', '---------'),
+ (self.c1.pk, 'Entertainment'),
+ (self.c2.pk, 'A test'),
+ (self.c3.pk, 'Third'),
+ ])
+
def test_num_queries(self):
"""
Widgets that render multiple subwidgets shouldn't make more than one