summaryrefslogtreecommitdiff
path: root/tests/model_forms/tests.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2017-06-28 20:30:19 -0700
committerJon Dufresne <jon.dufresne@gmail.com>2017-06-30 15:57:48 -0700
commita1be12fe193c8f3de8a0b0820f460a302472375f (patch)
treec91fc4242a996489ede8e72aeb1a9f6ba91c5695 /tests/model_forms/tests.py
parent5cbcb3683964205ce023157ca181d05a31be2ab5 (diff)
Fixed #28345 -- Applied limit_choices_to during ModelForm.__init__().
field_for_model() now has an additional keyword argument, apply_limit_choices_to, allowing it to continue to be used to create form fields dynamically after ModelForm.__init__() is called. Thanks Tim Graham for the review.
Diffstat (limited to 'tests/model_forms/tests.py')
-rw-r--r--tests/model_forms/tests.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
index 96f6d6985b..9a4ca57786 100644
--- a/tests/model_forms/tests.py
+++ b/tests/model_forms/tests.py
@@ -1,7 +1,7 @@
import datetime
import os
from decimal import Decimal
-from unittest import skipUnless
+from unittest import mock, skipUnless
from django import forms
from django.core.exceptions import (
@@ -2906,6 +2906,16 @@ class LimitChoicesToTests(TestCase):
fields = fields_for_model(StumpJoke, ['has_fooled_today'])
self.assertSequenceEqual(fields['has_fooled_today'].queryset, [self.threepwood])
+ def test_callable_called_each_time_form_is_instantiated(self):
+ field = StumpJokeForm.base_fields['most_recently_fooled']
+ with mock.patch.object(field, 'limit_choices_to') as today_callable_dict:
+ StumpJokeForm()
+ self.assertEqual(today_callable_dict.call_count, 1)
+ StumpJokeForm()
+ self.assertEqual(today_callable_dict.call_count, 2)
+ StumpJokeForm()
+ self.assertEqual(today_callable_dict.call_count, 3)
+
class FormFieldCallbackTests(SimpleTestCase):