diff options
| author | Jannis Leidel <jannis@leidel.info> | 2013-04-07 10:11:52 -0700 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2013-04-07 10:11:52 -0700 |
| commit | b5c0b3d1d9328e67baa9c7cc98ac38be3d94a0ec (patch) | |
| tree | b11ff5802383cfe41eb6c344df6d8ca704b7a8eb /tests | |
| parent | 5ab66dea50eab6625e3a07b71342268432e9cfaf (diff) | |
| parent | f9dc1379b874f80694a80e95f0f266a3d42f7368 (diff) | |
Merge pull request #1000 from bmispelon/ticket-15126
Fix #15126: Better error message when passing invalid options to ModelFo...
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/model_forms/tests.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index e8c638389b..96c3ecbdce 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -5,6 +5,7 @@ import os from decimal import Decimal from django import forms +from django.core.exceptions import FieldError from django.core.files.uploadedfile import SimpleUploadedFile from django.core.validators import ValidationError from django.db import connection @@ -228,6 +229,22 @@ class ModelFormBaseTest(TestCase): self.assertEqual(list(LimitFields.base_fields), ['url']) + def test_limit_nonexistent_field(self): + expected_msg = 'Unknown field(s) (nonexistent) specified for Category' + with self.assertRaisesMessage(FieldError, expected_msg): + class InvalidCategoryForm(forms.ModelForm): + class Meta: + model = Category + fields = ['nonexistent'] + + def test_limit_fields_with_string(self): + expected_msg = "CategoryForm.Meta.fields cannot be a string. Did you mean to type: ('url',)?" + with self.assertRaisesMessage(TypeError, expected_msg): + class CategoryForm(forms.ModelForm): + class Meta: + model = Category + fields = ('url') # note the missing comma + def test_exclude_fields(self): class ExcludeFields(forms.ModelForm): class Meta: @@ -237,6 +254,23 @@ class ModelFormBaseTest(TestCase): self.assertEqual(list(ExcludeFields.base_fields), ['name', 'slug']) + def test_exclude_nonexistent_field(self): + class ExcludeFields(forms.ModelForm): + class Meta: + model = Category + exclude = ['nonexistent'] + + self.assertEqual(list(ExcludeFields.base_fields), + ['name', 'slug', 'url']) + + def test_exclude_fields_with_string(self): + expected_msg = "CategoryForm.Meta.exclude cannot be a string. Did you mean to type: ('url',)?" + with self.assertRaisesMessage(TypeError, expected_msg): + class CategoryForm(forms.ModelForm): + class Meta: + model = Category + exclude = ('url') # note the missing comma + def test_confused_form(self): class ConfusedForm(forms.ModelForm): """ Using 'fields' *and* 'exclude'. Not sure why you'd want to do |
