Bump object-permissions to newest version 1.4.6.
[ganeti_webmgr.git] / django_test_tools / forms.py
blob04ed0541277d66baac87c8a6897decba5da5eefd
1 class FormTestMixin():
2 """
3 Test mixin for testing forms
4 """
6 def assert_missing_fields(self, cls, data, fields=None):
7 """
8 Tests fields that should raise a required exception
10 @param cls - form class
11 @param data - dict of valid data
12 @param fields - list of field names that are required
13 """
14 fields = data.keys if fields is None else fields
16 # check required fields
17 for name in fields:
18 data_ = data.copy()
19 del data_[name]
20 form = cls(data_)
21 self.assertFalse(form.is_valid())
23 def assert_invalid_value(self, cls, data, fields):
24 """
25 Tests fields that should raise an error for a specific type of invalid
26 data.
28 @param cls - form class
29 @param data - dict of valid data
30 @param fields - list of dicts containing field name and
31 values that result
32 in form errors.
33 """
34 # check required fields
35 for values in fields:
36 data_ = data.copy()
37 data_.update(values)
38 form = cls(data_)
39 self.assertFalse(form.is_valid())