diff options
| author | Emanuele Pucciarelli | 2014-04-29 21:41:53 +0200 |
|---|---|---|
| committer | Emanuele Pucciarelli | 2014-04-29 21:41:53 +0200 |
| commit | f54399ea778cd58a0eec111ef9380a7867a7d030 (patch) | |
| tree | 079623cedf694588b6c57769aef808e49395798f /rest_framework/tests/test_relations.py | |
| parent | 8904f179d1bc925d52001497e92b9cd509e65bd5 (diff) | |
| parent | 161270da992c13ff093048429d3d139f9bd0fc4e (diff) | |
| download | django-rest-framework-f54399ea778cd58a0eec111ef9380a7867a7d030.tar.bz2 | |
Merge remote-tracking branch 'upstream/master'
Conflicts:
rest_framework/tests/models.py
Diffstat (limited to 'rest_framework/tests/test_relations.py')
| -rw-r--r-- | rest_framework/tests/test_relations.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/rest_framework/tests/test_relations.py b/rest_framework/tests/test_relations.py index f52e0e1e..37ac826b 100644 --- a/rest_framework/tests/test_relations.py +++ b/rest_framework/tests/test_relations.py @@ -2,8 +2,10 @@ General tests for relational fields. """ from __future__ import unicode_literals +from django import get_version from django.db import models from django.test import TestCase +from django.utils import unittest from rest_framework import serializers from rest_framework.tests.models import BlogPost @@ -118,3 +120,25 @@ class RelatedFieldSourceTests(TestCase): (serializers.ModelSerializer,), attrs) with self.assertRaises(AttributeError): TestSerializer(data={'name': 'foo'}) + +@unittest.skipIf(get_version() < '1.6.0', 'Upstream behaviour changed in v1.6') +class RelatedFieldChoicesTests(TestCase): + """ + Tests for #1408 "Web browseable API doesn't have blank option on drop down list box" + https://github.com/tomchristie/django-rest-framework/issues/1408 + """ + def test_blank_option_is_added_to_choice_if_required_equals_false(self): + """ + + """ + post = BlogPost(title="Checking blank option is added") + post.save() + + queryset = BlogPost.objects.all() + field = serializers.RelatedField(required=False, queryset=queryset) + + choice_count = BlogPost.objects.count() + widget_count = len(field.widget.choices) + + self.assertEqual(widget_count, choice_count + 1, 'BLANK_CHOICE_DASH option should have been added') + |
