示例#1
0
    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)
示例#2
0
    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]))
示例#3
0
 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,
                                     [])
示例#4
0
 def _formfield(self, initial):
     return ChoiceOrCharField(choices=self._args['choices'],
                              initial=initial)
示例#5
0
 def test_ok_choice(self):
     field = ChoiceOrCharField(choices=enumerate(self._team, start=1))
     self.assertEqual((1, 'Naruto'), field.clean([1, '']))
示例#6
0
 def test_empty_other(self):
     field = ChoiceOrCharField(choices=enumerate(self._team, start=1))
     self.assertFieldValidationError(ChoiceOrCharField, 'invalid_other',
                                     field.clean, [0, ''])