diff options
| author | Tom Christie | 2013-05-18 14:45:06 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-05-18 14:45:06 +0100 |
| commit | 304c07681d256c4e3c6e1e1485bf9b905ba431fb (patch) | |
| tree | 46c9c269d6e7b3faa8890f05e2c066420e872e55 /rest_framework/tests/fields.py | |
| parent | 275bfa2320eeffcfd307daaf7c85faaa0f55a8ee (diff) | |
| parent | a0e3c44c99a61a6dc878308bdf0890fbb10c41e4 (diff) | |
| download | django-rest-framework-304c07681d256c4e3c6e1e1485bf9b905ba431fb.tar.bz2 | |
Merge
Diffstat (limited to 'rest_framework/tests/fields.py')
| -rw-r--r-- | rest_framework/tests/fields.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/rest_framework/tests/fields.py b/rest_framework/tests/fields.py index 5b5ce835..6b1cdfc7 100644 --- a/rest_framework/tests/fields.py +++ b/rest_framework/tests/fields.py @@ -659,3 +659,29 @@ class DecimalFieldTest(TestCase): self.assertFalse(s.is_valid()) 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) |
