simple test demonstrating the issue

This commit is contained in:
jeffrey k eliasen 2018-06-12 16:34:15 -10:00
parent a21484d90e
commit 3e05a5c0ca
2 changed files with 20 additions and 1 deletions

View File

@ -1397,7 +1397,7 @@ class ChoiceField(Field):
html_cutoff_text = _('More than {count} items...') html_cutoff_text = _('More than {count} items...')
def __init__(self, choices, **kwargs): def __init__(self, choices, **kwargs):
self.choices = choices self._choices = choices
self.html_cutoff = kwargs.pop('html_cutoff', self.html_cutoff) self.html_cutoff = kwargs.pop('html_cutoff', self.html_cutoff)
self.html_cutoff_text = kwargs.pop('html_cutoff_text', self.html_cutoff_text) self.html_cutoff_text = kwargs.pop('html_cutoff_text', self.html_cutoff_text)

View File

@ -1,6 +1,7 @@
import datetime import datetime
import os import os
import re import re
import sys
import unittest import unittest
import uuid import uuid
from decimal import ROUND_DOWN, ROUND_UP, Decimal from decimal import ROUND_DOWN, ROUND_UP, Decimal
@ -25,6 +26,13 @@ try:
except ImportError: except ImportError:
typings = False typings = False
if sys.version_info[0] < 3:
# python 2
import mock
else:
# python 3
from unittest import mock
# Tests for helper functions. # Tests for helper functions.
# --------------------------- # ---------------------------
@ -1524,6 +1532,17 @@ class TestChoiceField(FieldValues):
] ]
) )
@mock.patch('rest_framework.fields.ChoiceField.choices')
def test_set_initial_choices(self, choices_mock):
field = serializers.ChoiceField(
allow_null=True,
choices=[
1, 2,
]
)
assert field._choices == [1, 2]
assert field.choices == choices_mock
def test_allow_blank(self): def test_allow_blank(self):
""" """
If `allow_blank=True` then '' is a valid input. If `allow_blank=True` then '' is a valid input.