Ticket #14467: AllValuesFilterSpec_Null_Tests.py

File AllValuesFilterSpec_Null_Tests.py, 2.4 KB (added by oyvind, 14 years ago)

Start of tests for patch, not sure where to put them

Line 
1from django.db import models
2
3class OptionalAge(models.Model):
4 name = models.CharField(max_length=25)
5 age = models.PositiveIntegerField(null=True, blank=True)
6
7from django.contrib import admin
8from django.contrib.admin.views.main import ChangeList
9
10class AllValuesFilterSpecTest(TestCase):
11
12 def setUp(self):
13 OptionalAge.objects.create(name='Sam', age=35)
14 OptionalAge.objects.create(name='Tilk', age=135)
15 OptionalAge.objects.create(name='Oneill', age=None)
16
17 def testAllValuesFilterSpecTest(self):
18
19 m = OptionalAgeAdmin(OptionalAge, admin.site)
20
21 r = MockRequest()
22 r.GET = {'age__isnull': 'True'}
23
24 cl = ChangeList(r, OptionalAge, m.list_display, m.list_display_links,
25 m.list_filter, m.date_hierarchy, m.search_fields,
26 m.list_select_related, m.list_per_page, m.list_editable, m)
27
28 filterspec = cl.get_filters(r)[0][0]
29
30 choices = filterspec.choices(cl)
31 self.assertEquals(choices[3].selected, True)
32 self.assertContains(choices[3].query_string, 'age__isnull=True')
33
34 r = MockRequest()
35 r.GET = {'age': '35'}
36
37 cl = ChangeList(r, OptionalAge, m.list_display, m.list_display_links,
38 m.list_filter, m.date_hierarchy, m.search_fields,
39 m.list_select_related, m.list_per_page, m.list_editable, m)
40
41 filterspec = cl.get_filters(r)[0][0]
42
43 choices = filterspec.choices(cl)
44 self.assertEquals(choices[1].selected, True)
45 self.assertContains(choices[1].query_string, 'age=35')
46
47 r = MockRequest()
48 r.GET = {'age': '135'}
49
50 cl = ChangeList(r, OptionalAge, m.list_display, m.list_display_links,
51 m.list_filter, m.date_hierarchy, m.search_fields,
52 m.list_select_related, m.list_per_page, m.list_editable, m)
53
54 filterspec = cl.get_filters(r)[0][0]
55
56 choices = filterspec.choices(cl)
57 self.assertEquals(choices[2].selected, True)
58 self.assertContains(choices[2].query_string, 'age=135')
59
60
61 def tearDown(self):
62 OptionalAge.objects.all().delete()
63
64class OptionalAgeAdmin(admin.ModelAdmin):
65 list_filter = ('age',)
66
67class MockRequest(object):
68 GET = {}
Back to Top