diff options
| author | Claude Paroz <claude@2xlibre.net> | 2016-02-20 14:40:07 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2016-02-21 00:24:20 +0100 |
| commit | d43156e1e984d7e0848b7d4db218877a29d617b4 (patch) | |
| tree | 689f1d81d61f47cf85dce6e8e1807aa08a2b6dcc /tests | |
| parent | 6670da75ff8a59b2ec0b465846e3f76aab9155b2 (diff) | |
Fixed #26238 -- Raised explicit error for non-editable field in ModelForm
Thanks Luke Crouch for the report and Simon Charette for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_forms/tests.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index 968407e845..a2e7c66419 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -2282,6 +2282,21 @@ class ModelOtherFieldTests(SimpleTestCase): self.assertTrue(HomepageForm({'url': 'http://www.example.com:8000/test'}).is_valid()) self.assertTrue(HomepageForm({'url': 'http://example.com/foo/bar'}).is_valid()) + def test_modelform_non_editable_field(self): + """ + When explicitely including a non-editable field in a ModelForm, the + error message should be explicit. + """ + # 'created', non-editable, is excluded by default + self.assertNotIn('created', ArticleForm().fields) + + msg = "'created' cannot be specified for Article model form as it is a non-editable field" + with self.assertRaisesMessage(FieldError, msg): + class InvalidArticleForm(forms.ModelForm): + class Meta: + model = Article + fields = ('headline', 'created') + def test_http_prefixing(self): """ If the http:// prefix is omitted on form input, the field adds it again. (Refs #13613) |
