Ticket #6967: 6967-tests.diff
File 6967-tests.diff, 1.4 KB (added by , 16 years ago) |
---|
-
tests/modeltests/model_forms/models.py
27 27 (3, 'Live'), 28 28 ) 29 29 30 ARTICLE_STATUS_CHAR = ( 31 ('d', 'Draft'), 32 ('p', 'Pending'), 33 ('l', 'Live'), 34 ) 35 30 36 class Category(models.Model): 31 37 name = models.CharField(max_length=20) 32 38 slug = models.SlugField(max_length=20) … … 111 117 def __unicode__(self): 112 118 return self.field 113 119 120 class ArticleStatus(models.Model): 121 status = models.CharField(max_length=2, choices=ARTICLE_STATUS_CHAR, blank=True, null=True) 122 114 123 __test__ = {'API_TESTS': """ 115 124 >>> from django import forms 116 125 >>> from django.forms.models import ModelForm, model_to_dict … … 1123 1132 >>> f.clean('1') 1124 1133 u'1' 1125 1134 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') 1142 Traceback (most recent call last): 1143 ... 1144 ValidationError: [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') 1151 Traceback (most recent call last): 1152 ... 1153 ValidationError: [u'Select a valid choice. z is not one of the available choices.'] 1154 1126 1155 """}