diff options
| author | Pablo Recio | 2013-05-18 12:40:25 +0200 |
|---|---|---|
| committer | Pablo Recio | 2013-05-18 12:41:52 +0200 |
| commit | ab8bd566f9db327a4c463317011818d421bbf89c (patch) | |
| tree | 0ee831228591b1a7ad10636539d1f6592ba6f6a1 /rest_framework/tests/fields.py | |
| parent | de5cc8de423a22009d2a643f6c268805f715b212 (diff) | |
| download | django-rest-framework-ab8bd566f9db327a4c463317011818d421bbf89c.tar.bz2 | |
Adding `BLANK_CHOICE_DASH` as a choice if the model's field isn't required
Diffstat (limited to 'rest_framework/tests/fields.py')
| -rw-r--r-- | rest_framework/tests/fields.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/rest_framework/tests/fields.py b/rest_framework/tests/fields.py index 3cdfa0f6..f313ba60 100644 --- a/rest_framework/tests/fields.py +++ b/rest_framework/tests/fields.py @@ -645,4 +645,30 @@ class DecimalFieldTest(TestCase): s = DecimalSerializer(data={'decimal_field': '12345.6'}) self.assertFalse(s.is_valid()) - self.assertEqual(s.errors, {'decimal_field': ['Ensure that there are no more than 4 digits in total.']})
\ No newline at end of file + self.assertEqual(s.errors, {'decimal_field': ['Ensure that there are no more than 4 digits in total.']}) + + +class ChoiceFieldTests(TestCase): + """ + Tests for the ChoiceField options generator + """ + + SAMPLE_CHOICES = [ + ('red', 'Red'), + ('green', 'Green'), + ('blue', 'Blue'), + ] + + def test_choices_required(self): + """ + Make sure proper choices are rendered if field is required + """ + f = serializers.ChoiceField(required=True, choices=self.SAMPLE_CHOICES) + self.assertEqual(f.choices, self.SAMPLE_CHOICES) + + def test_choices_not_required(self): + """ + Make sure proper choices (plus blank) are rendered if the field isn't required + """ + f = serializers.ChoiceField(required=False, choices=self.SAMPLE_CHOICES) + self.assertEqual(f.choices, models.fields.BLANK_CHOICE_DASH + self.SAMPLE_CHOICES) |
