Ticket #4415: 4415_tests.diff

File 4415_tests.diff, 973 bytes (added by oggie_rob, 17 years ago)

Test of positive integer values via form_for_model. Used generic "boundary" model which can be extended.

  • tests/modeltests/model_forms/models.py

     
    7070    def __unicode__(self):
    7171        return self.phone
    7272
     73class BoundaryModel(models.Model):
     74    positive_integer = models.PositiveIntegerField(null=True, blank=True)
     75
    7376__test__ = {'API_TESTS': """
    7477>>> from django.newforms import form_for_model, form_for_instance, save_instance, BaseForm, Form, CharField
    7578>>> import datetime
     
    560563True
    561564>>> f.cleaned_data
    562565{'phone': u'312-555-1212', 'description': u'Assistance'}
     566
     567# Boundary conditions / validation ############################################
     568>>> BoundaryForm = form_for_model(BoundaryModel)
     569>>> f = BoundaryForm({'positive_integer':100})
     570>>> f.is_valid()
     571True
     572>>> f = BoundaryForm({'positive_integer':-100})
     573>>> f.is_valid()
     574False
Back to Top