コード例 #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
ファイル: test_form_fields.py プロジェクト: ziegeer/kitsune
 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.assertRaisesErrorWithMessage(
         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_typedmultiplechoicefield_75(self):
     # Non-required fields aren't required
     f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")],
                                  coerce=int, required=False)
     eq_([], f.clean([]))
コード例 #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']))
コード例 #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']))
コード例 #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']))
コード例 #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']))