def test_empty_ok(self): field = ChoiceOrCharField(choices=enumerate(self._team, start=1), required=False) with self.assertNoException(): cleaned = field.clean(['', '']) self.assertEqual((None, None), cleaned)
def test_ok_other(self): field = ChoiceOrCharField(choices=enumerate(self._team, start=1)) with self.assertNoException(): choices = field.choices self.assertIn((0, _('Other')), choices) other = 'Shikamaru' self.assertEqual((0, other), field.clean([0, other]))
def test_empty_required(self): clean = ChoiceOrCharField(choices=enumerate(self._team, start=1)).clean self.assertFieldValidationError(ChoiceOrCharField, 'required', clean, None) self.assertFieldValidationError(ChoiceOrCharField, 'required', clean, '') self.assertFieldValidationError(ChoiceOrCharField, 'required', clean, [])
def _formfield(self, initial): return ChoiceOrCharField(choices=self._args['choices'], initial=initial)
def test_ok_choice(self): field = ChoiceOrCharField(choices=enumerate(self._team, start=1)) self.assertEqual((1, 'Naruto'), field.clean([1, '']))
def test_empty_other(self): field = ChoiceOrCharField(choices=enumerate(self._team, start=1)) self.assertFieldValidationError(ChoiceOrCharField, 'invalid_other', field.clean, [0, ''])