1 from ..forms
import BaseLookupForm
2 from .base
import BaseSelectableTestCase
6 'BaseLookupFormTestCase',
10 class BaseLookupFormTestCase(BaseSelectableTestCase
):
12 def get_valid_data(self
):
19 def test_valid_data(self
):
20 data
= self
.get_valid_data()
21 form
= BaseLookupForm(data
)
22 self
.assertTrue(form
.is_valid(), "%s" % form
.errors
)
24 def test_invalid_limit(self
):
26 Test giving the form an invalid limit.
29 data
= self
.get_valid_data()
31 form
= BaseLookupForm(data
)
32 self
.assertFalse(form
.is_valid())
34 def test_no_limit(self
):
36 If SELECTABLE_MAX_LIMIT is set and limit is not given then
37 the form will return SELECTABLE_MAX_LIMIT.
40 with self
.settings(SELECTABLE_MAX_LIMIT
=25):
41 data
= self
.get_valid_data()
44 form
= BaseLookupForm(data
)
45 self
.assertTrue(form
.is_valid(), "%s" % form
.errors
)
46 self
.assertEqual(form
.cleaned_data
['limit'], 25)
48 def test_no_max_set(self
):
50 If SELECTABLE_MAX_LIMIT is not set but given then the form
51 will return the given limit.
54 with self
.settings(SELECTABLE_MAX_LIMIT
=None):
55 data
= self
.get_valid_data()
56 form
= BaseLookupForm(data
)
57 self
.assertTrue(form
.is_valid(), "%s" % form
.errors
)
59 self
.assertTrue(form
.cleaned_data
['limit'], data
['limit'])
61 def test_no_max_set_not_given(self
):
63 If SELECTABLE_MAX_LIMIT is not set and not given then the form
67 with self
.settings(SELECTABLE_MAX_LIMIT
=None):
68 data
= self
.get_valid_data()
71 form
= BaseLookupForm(data
)
72 self
.assertTrue(form
.is_valid(), "%s" % form
.errors
)
73 self
.assertFalse(form
.cleaned_data
.get('limit'))
75 def test_over_limit(self
):
77 If SELECTABLE_MAX_LIMIT is set and limit given is greater then
78 the form will return SELECTABLE_MAX_LIMIT.
81 with self
.settings(SELECTABLE_MAX_LIMIT
=25):
82 data
= self
.get_valid_data()
84 form
= BaseLookupForm(data
)
85 self
.assertTrue(form
.is_valid(), "%s" % form
.errors
)
86 self
.assertEqual(form
.cleaned_data
['limit'], 25)