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([]))
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'])
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'])
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']))
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([]))
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']))
def test_typedmultiplechoicefield_72(self): # Different coercion, same validation. f = TypedMultipleChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=float) eq_([1.0], f.clean(['1']))