Ticket #5505: fixed-test.diff

File fixed-test.diff, 1.6 KB (added by Malcolm Tredinnick, 17 years ago)

Corrected version of Dan Larkin's test

  • tests/regressiontests/forms/models.py

    diff --git a/tests/regressiontests/forms/models.py b/tests/regressiontests/forms/models.py
    index f4f8607..0f55170 100644
    a b  
    11from django.db import models
    22
    3 class BoundaryModel(models.Model): 
     3class BoundaryModel(models.Model):
    44    positive_integer = models.PositiveIntegerField(null=True, blank=True)
    5    
     5
     6class ForeignKeyModel(models.Model):
     7    foreign_key = models.ForeignKey('self', null=True, blank=True)
     8
    69__test__ = {'API_TESTS': """
    710>>> from django.newforms import form_for_model
    811
    912# Boundary conditions on a PostitiveIntegerField #########################
    10 >>> BoundaryForm = form_for_model(BoundaryModel) 
    11 >>> f = BoundaryForm({'positive_integer':100}) 
    12 >>> f.is_valid() 
     13>>> BoundaryForm = form_for_model(BoundaryModel)
     14>>> f = BoundaryForm({'positive_integer':100})
     15>>> f.is_valid()
    1316True
    14 >>> f = BoundaryForm({'positive_integer':0}) 
    15 >>> f.is_valid() 
     17>>> f = BoundaryForm({'positive_integer':0})
     18>>> f.is_valid()
    1619True
    17 >>> f = BoundaryForm({'positive_integer':-100}) 
    18 >>> f.is_valid() 
     20>>> f = BoundaryForm({'positive_integer':-100})
     21>>> f.is_valid()
    1922False
    2023
    21 """}
    22  No newline at end of file
     24>>> from django.newforms import form_for_instance
     25>>> fk1 = ForeignKeyModel()
     26>>> fk1.save()
     27>>> fk2 = ForeignKeyModel(foreign_key=fk1)
     28>>> fk2.save()
     29>>> fk2.foreign_key == fk1
     30True
     31>>> Form = form_for_instance(fk1, formfield_callback=lambda f, initial: f.formfield(initial=initial))
     32>>> f = Form()
     33>>> f.is_valid()
     34False
     35>>> f = Form({'foreign_key': fk1.pk})
     36>>> f.is_valid()
     37True
     38>>> f.errors
     39{}
     40"""}
Back to Top