Exemplo 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([]))
Exemplo 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([]))
Exemplo 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'])
Exemplo 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'])
Exemplo 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([]))
Exemplo 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']))
Exemplo 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']))
Exemplo 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']))
Exemplo 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([]))
Exemplo 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']))
Exemplo 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']))
Exemplo 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']))