Esempio n. 1
0
 def test_typedmultiplechoicefield_76(self):
     # If you want cleaning an empty value to return a different type,
     # tell the field
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=int, required=False,
                                  empty_value=None)
     eq_(None, f.clean([]))
Esempio n. 2
0
 def test_typedmultiplechoicefield_76(self):
     # If you want cleaning an empty value to return a different type,
     # tell the field
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=int, required=False,
                                  empty_value=None)
     eq_(None, f.clean([]))
Esempio n. 3
0
 def test_typedmultiplechoicefield_71(self):
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=int)
     eq_([1], f.clean(['1']))
     self.assertRaisesErrorWithMessage(
         ValidationError,
         "[u'Select a valid choice. 2 is not one of the available choices."
         "']", f.clean, ['2'])
Esempio n. 4
0
 def test_typedmultiplechoicefield_71(self):
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=int)
     eq_([1], f.clean(['1']))
     self.assertRaisesErrorWithMessage(
         ValidationError,
         "[u'Select a valid choice. 2 is not one of the available choices."
         "']", f.clean, ['2'])
Esempio n. 5
0
 def test_typedmultiplechoicefield_75(self):
     # Non-required fields aren't required
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=int, required=False)
     eq_([], f.clean([]))
Esempio n. 6
0
 def test_typedmultiplechoicefield_73(self):
     # This can also cause weirdness: bool(-1) == True
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=bool)
     eq_([True], f.clean(['-1']))
Esempio n. 7
0
 def test_typedmultiplechoicefield_72(self):
     # Different coercion, same validation.
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=float)
     eq_([1.0], f.clean(['1']))
Esempio n. 8
0
 def test_coerce_only(self):
     """No validation error raised in this case."""
     f = TypedMultipleChoiceField(choices=[(1, '+1')], coerce=int,
                                  coerce_only=True)
     eq_([], f.clean(['2']))
Esempio n. 9
0
 def test_typedmultiplechoicefield_75(self):
     # Non-required fields aren't required
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=int,
                                  required=False)
     eq_([], f.clean([]))
Esempio n. 10
0
 def test_typedmultiplechoicefield_73(self):
     # This can also cause weirdness: bool(-1) == True
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=bool)
     eq_([True], f.clean(['-1']))
Esempio n. 11
0
 def test_typedmultiplechoicefield_72(self):
     # Different coercion, same validation.
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=float)
     eq_([1.0], f.clean(['1']))
Esempio n. 12
0
 def test_coerce_only(self):
     """No validation error raised in this case."""
     f = TypedMultipleChoiceField(choices=[(1, '+1')],
                                  coerce=int,
                                  coerce_only=True)
     eq_([], f.clean(['2']))