diff options
| author | José Padilla | 2014-12-09 09:25:06 -0400 | 
|---|---|---|
| committer | José Padilla | 2014-12-09 09:25:06 -0400 | 
| commit | afe7ed9333e37384f8ddc57e891da9632c8714c3 (patch) | |
| tree | c45f1a1242b9c12f4e1e3aaaab2ff6eb90473ed9 /tests | |
| parent | 0f080bc2932095bc6dd2c71f545f2b588985431d (diff) | |
| download | django-rest-framework-afe7ed9333e37384f8ddc57e891da9632c8714c3.tar.bz2 | |
Add allow_blank for ChoiceField #2184
This makes a ChoiceField optional in HTML if
model field has `blank=True` set.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_fields.py | 15 | 
1 files changed, 15 insertions, 0 deletions
| diff --git a/tests/test_fields.py b/tests/test_fields.py index 13525632..3f4e65f2 100644 --- a/tests/test_fields.py +++ b/tests/test_fields.py @@ -804,6 +804,21 @@ class TestChoiceField(FieldValues):          ]      ) +    def test_allow_blank(self): +        """ +        If `allow_blank=True` then '' is a valid input. +        """ +        field = serializers.ChoiceField( +            allow_blank=True, +            choices=[ +                ('poor', 'Poor quality'), +                ('medium', 'Medium quality'), +                ('good', 'Good quality'), +            ] +        ) +        output = field.run_validation('') +        assert output is '' +  class TestChoiceFieldWithType(FieldValues):      """ | 
