Ticket #6967: 6967-tests.diff

File 6967-tests.diff, 1.4 KB (added by Matt McClanahan, 16 years ago)

Some tests for choices on CharField and IntegerField.

  • tests/modeltests/model_forms/models.py

     
    2727    (3, 'Live'),
    2828)
    2929
     30ARTICLE_STATUS_CHAR = (
     31    ('d', 'Draft'),
     32    ('p', 'Pending'),
     33    ('l', 'Live'),
     34)
     35
    3036class Category(models.Model):
    3137    name = models.CharField(max_length=20)
    3238    slug = models.SlugField(max_length=20)
     
    111117    def __unicode__(self):
    112118        return self.field
    113119
     120class ArticleStatus(models.Model):
     121    status = models.CharField(max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True)
     122
    114123__test__ = {'API_TESTS': """
    115124>>> from django import forms
    116125>>> from django.forms.models import ModelForm, model_to_dict
     
    11231132>>> f.clean('1')
    11241133u'1'
    11251134
     1135# Choices on CharField and IntegerField
     1136
     1137>>> class ArticleForm(ModelForm):
     1138...     class Meta:
     1139...         model = Article
     1140>>> f = ArticleForm()
     1141>>> f.fields['status'].clean('42')
     1142Traceback (most recent call last):
     1143...
     1144ValidationError: [u'Select a valid choice. 42 is not one of the available choices.']
     1145
     1146>>> class ArticleStatusForm(ModelForm):
     1147...     class Meta:
     1148...         model = ArticleStatus
     1149>>> f = ArticleStatusForm()
     1150>>> f.fields['status'].clean('z')
     1151Traceback (most recent call last):
     1152...
     1153ValidationError: [u'Select a valid choice. z is not one of the available choices.']
     1154
    11261155"""}
Back to Top