mirror of
https://github.com/django/django.git
synced 2024-11-19 07:54:07 +00:00
e488c1dc0d
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12590 bcc190cf-cafb-0310-a4f2-bffc1f526a37
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
from django.test import TestCase
|
|
from django import forms
|
|
from models import Category
|
|
|
|
|
|
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.
|
|
"""
|
|
url = forms.CharField(required=False)
|
|
|
|
class Meta:
|
|
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_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()
|
|
|