Ticket #8556: 8556-tests.diff

File 8556-tests.diff, 1.2 KB (added by kratorius, 7 years ago)

Unit tests for this ticket

  • tests/modeltests/model_forms/models.py

     
    9898    def __unicode__(self):
    9999        return self.description
    100100
     101class CommaSeparatedInteger(models.Model):
     102    field = models.CommaSeparatedIntegerField(max_length=20)
     103
     104    def __unicode__(self):
     105        return self.field
     106
    101107__test__ = {'API_TESTS': """
    102108>>> from django import forms
    103109>>> from django.forms.models import ModelForm, model_to_dict
     
    10501056<link href="/some/form/css" type="text/css" media="all" rel="stylesheet" />
    10511057<script type="text/javascript" src="/some/form/javascript"></script>
    10521058
     1059>>> class CommaSeparatedIntegerForm(ModelForm):
     1060...    class Meta:
     1061...        model = CommaSeparatedInteger
     1062
     1063>>> f = CommaSeparatedIntegerForm().fields['field']
     1064>>> f.clean('1,2,3')
     1065u'1,2,3'
     1066>>> f.clean('1a,2')
     1067Traceback (most recent call last):
     1068...
     1069ValidationError: [u'Enter a valid value.']
     1070>>> f.clean(',,,,')
     1071u',,,,'
     1072>>> f.clean('1.2')
     1073Traceback (most recent call last):
     1074...
     1075ValidationError: [u'Enter a valid value.']
     1076>>> f.clean('1,,2')
     1077u'1,,2'
     1078>>> f.clean('1')
     1079u'1'
     1080
    10531081"""}
Back to Top