diff options
Diffstat (limited to 'tests/model_forms')
| -rw-r--r-- | tests/model_forms/test_modelchoicefield.py | 30 | ||||
| -rw-r--r-- | tests/model_forms/tests.py | 2 |
2 files changed, 20 insertions, 12 deletions
diff --git a/tests/model_forms/test_modelchoicefield.py b/tests/model_forms/test_modelchoicefield.py index 733175823f..975873c7f9 100644 --- a/tests/model_forms/test_modelchoicefield.py +++ b/tests/model_forms/test_modelchoicefield.py @@ -96,6 +96,25 @@ class ModelChoiceFieldTests(TestCase): (self.c3.pk, 'category Third'), ]) + def test_choices_freshness(self): + f = forms.ModelChoiceField(Category.objects.all()) + self.assertEqual(len(f.choices), 4) + self.assertEqual(list(f.choices), [ + ('', '---------'), + (self.c1.pk, 'Entertainment'), + (self.c2.pk, 'A test'), + (self.c3.pk, 'Third'), + ]) + c4 = Category.objects.create(name='Fourth', slug='4th', url='4th') + self.assertEqual(len(f.choices), 5) + self.assertEqual(list(f.choices), [ + ('', '---------'), + (self.c1.pk, 'Entertainment'), + (self.c2.pk, 'A test'), + (self.c3.pk, 'Third'), + (c4.pk, 'Fourth'), + ]) + def test_deepcopies_widget(self): class ModelChoiceForm(forms.Form): category = forms.ModelChoiceField(Category.objects.all()) @@ -257,17 +276,6 @@ 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 diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 4276bc68f1..1d6d9efa96 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -2345,7 +2345,7 @@ class OtherModelFormTests(TestCase): return ', '.join(c.name for c in obj.colours.all()) field = ColorModelChoiceField(ColourfulItem.objects.prefetch_related('colours')) - with self.assertNumQueries(2): # would be 3 if prefetch is ignored + with self.assertNumQueries(3): # would be 4 if prefetch is ignored self.assertEqual(tuple(field.choices), ( ('', '---------'), (multicolor_item.pk, 'blue, red'), |
