예제 #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([]))
예제 #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([]))
예제 #3
0
 def test_typedmultiplechoicefield_71(self):
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=int)
     eq_([1], f.clean(['1']))
     self.assertRaisesMessage(
         ValidationError,
         "[u'Select a valid choice. 2 is not one of the available choices."
         "']", f.clean, ['2'])
예제 #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'])
예제 #5
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']))
예제 #6
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([]))
예제 #7
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']))
예제 #8
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']))
예제 #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([]))
예제 #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']))
예제 #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']))
예제 #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']))