From bfe18e6a0a45a73a92cce994f06206fc2839cada Mon Sep 17 00:00:00 2001
From: Javed Khan <javed@agiliq.com>
Date: Sat, 29 Dec 2012 21:14:50 +0530
Subject: [PATCH] refs #18573: added test for default formfield_callback
---
tests/regressiontests/model_forms_regress/tests.py | 25 ++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py
index 90c907f..1545c59 100644
a
|
b
|
class FormFieldCallbackTests(TestCase):
|
315 | 315 | self.assertEqual(callback_args, |
316 | 316 | [(id_field, {}), (name_field, {'widget': widget})]) |
317 | 317 | |
| 318 | def test_default_modelform_callback(self): |
| 319 | """Test that formfield_callback defaults to the modelform formfield_callback""" |
| 320 | |
| 321 | callback_args = [] |
| 322 | |
| 323 | def callback(db_field, **kwargs): |
| 324 | callback_args.append((db_field, kwargs)) |
| 325 | return db_field.formfield(**kwargs) |
| 326 | |
| 327 | widget = forms.Textarea() |
| 328 | |
| 329 | class BaseForm(forms.ModelForm): |
| 330 | |
| 331 | formfield_callback = callback |
| 332 | |
| 333 | class Meta: |
| 334 | model = Person |
| 335 | widgets = {'name': widget} |
| 336 | |
| 337 | _ = modelform_factory(Person, form=BaseForm) |
| 338 | id_field, name_field = Person._meta.fields |
| 339 | |
| 340 | self.assertEqual(callback_args, |
| 341 | [(id_field, {}), (name_field, {'widget': widget})]) |
| 342 | |
318 | 343 | def test_bad_callback(self): |
319 | 344 | # A bad callback provided by user still gives an error |
320 | 345 | self.assertRaises(TypeError, modelform_factory, Person, |