summaryrefslogtreecommitdiff
path: root/tests/modeltests/model_forms/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/modeltests/model_forms/tests.py')
-rw-r--r--tests/modeltests/model_forms/tests.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py
index 49ea314bc6..53060105c7 100644
--- a/tests/modeltests/model_forms/tests.py
+++ b/tests/modeltests/model_forms/tests.py
@@ -3,7 +3,7 @@ from django import forms
from models import Category
-class IncompleteCategoryForm(forms.ModelForm):
+class IncompleteCategoryFormWithFields(forms.ModelForm):
"""
A form that replaces the model's url field with a custom one. This should
prevent the model field's validation from being called.
@@ -14,8 +14,24 @@ class IncompleteCategoryForm(forms.ModelForm):
fields = ('name', 'slug')
model = Category
+class IncompleteCategoryFormWithExclude(forms.ModelForm):
+ """
+ A form that replaces the model's url field with a custom one. This should
+ prevent the model field's validation from being called.
+ """
+ url = forms.CharField(required=False)
+
+ class Meta:
+ exclude = ['url']
+ model = Category
+
+
class ValidationTest(TestCase):
- def test_validates_with_replaced_field(self):
- form = IncompleteCategoryForm(data={'name': 'some name', 'slug': 'some-slug'})
+ def test_validates_with_replaced_field_not_specified(self):
+ form = IncompleteCategoryFormWithFields(data={'name': 'some name', 'slug': 'some-slug'})
+ assert form.is_valid()
+
+ def test_validates_with_replaced_field_excluded(self):
+ form = IncompleteCategoryFormWithExclude(data={'name': 'some name', 'slug': 'some-slug'})
assert form.is_valid()