Ticket #27039: 27039-test.diff

File 27039-test.diff, 850 bytes (added by Tim Graham, 8 years ago)
  • tests/model_forms/tests.py

    diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py
    index f03c80f..4c13740 100644
    a b class ModelFormBaseTest(TestCase):  
    549549        self.assertEqual(list(OrderFields2.base_fields),
    550550                         ['slug', 'name'])
    551551
     552    def test_default_populated_on_optional_field(self):
     553        class PubForm(forms.ModelForm):
     554            mode = forms.CharField(max_length=255, required=False)
     555
     556            class Meta:
     557                model = PublicationDefaults
     558                fields = ('mode',)
     559
     560        mf = PubForm({})
     561        self.assertEqual(mf.errors, {})
     562        m = mf.save(commit=False)
     563        self.assertEqual(m.mode, 'di')  # from the model field default
     564
    552565
    553566class FieldOverridesByFormMetaForm(forms.ModelForm):
    554567    class Meta:
Back to Top