Ticket #9209: models.py

File models.py, 1.1 KB (added by Rozza, 16 years ago)

Test to display the bug

Line 
1from django.db import models
2from django import forms
3
4class Department(models.Model):
5 name = models.CharField(max_length=200, blank=False)
6
7class PeopleSearchForm(forms.Form):
8 people_s = forms.CharField(label='Search', required=False)
9 people_d = forms.ModelChoiceField(queryset=Department.objects.all(), empty_label='-- department --', required=False)
10 people_z = forms.ModelMultipleChoiceField(queryset=Department.objects.all(), required=False)
11
12
13__test__ = {'API_TESTS':"""
14
15>>> Department.objects.create(name='Monty')
16<Department: Department object>
17>>> Department.objects.create(name='Brian')
18<Department: Department object>
19
20# Pass data to the PeopleSearchForm #
21# Empty Form
22>>> f = PeopleSearchForm({})
23>>> f.is_valid()
24True
25
26# Valid search
27>>> f = PeopleSearchForm({'people_s': 'Monty'})
28>>> f.is_valid()
29True
30
31# Invalid department search
32>>> f = PeopleSearchForm({'people_d': 'Monty'})
33>>> f.is_valid()
34False
35
36# Valid department multiple select
37>>> f = PeopleSearchForm({'people_z': [1,2]})
38>>> f.is_valid()
39True
40
41# invalid department multiple select
42>>> f = PeopleSearchForm({'people_z': ['monty']})
43>>> f.is_valid()
44False
45"""}
Back to Top