Ticket #12285: 12285-unit-test-ValueError.diff

File 12285-unit-test-ValueError.diff, 1.3 KB (added by tobias, 6 years ago)

updated patch uses 'is None' and applies against trunk

  • django/forms/models.py

    diff -r ee4db7b4f9ef django/forms/models.py
    a b  
    236236                 empty_permitted=False, instance=None):
    237237        opts = self._meta
    238238        if instance is None:
     239            if opts.model is None:
     240                raise ValueError('ModelForm has no model class specified')
    239241            # if we didn't get an instance, instantiate a new one
    240242            self.instance = opts.model()
    241243            object_data = {}
  • tests/regressiontests/model_forms_regress/tests.py

    diff -r ee4db7b4f9ef tests/regressiontests/model_forms_regress/tests.py
    a b  
    145145        data = {'name': 'anonymous'}
    146146        form = RealPersonForm(data)
    147147        self.assertEqual(form.is_valid(), False)
    148         self.assertEqual(form.errors['__all__'], ['Please specify a real name.']) 
     148        self.assertEqual(form.errors['__all__'], ['Please specify a real name.'])
    149149
     150class ModelClassTests(TestCase):
     151    def test_no_model_class(self):
     152        class NoModelModelForm(forms.ModelForm):
     153            pass
     154        self.assertRaises(ValueError, NoModelModelForm)
Back to Top