mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 03:20:12 +03:00
simple test demonstrating the issue
This commit is contained in:
parent
a21484d90e
commit
3e05a5c0ca
|
@ -1397,7 +1397,7 @@ class ChoiceField(Field):
|
|||
html_cutoff_text = _('More than {count} items...')
|
||||
|
||||
def __init__(self, choices, **kwargs):
|
||||
self.choices = choices
|
||||
self._choices = choices
|
||||
self.html_cutoff = kwargs.pop('html_cutoff', self.html_cutoff)
|
||||
self.html_cutoff_text = kwargs.pop('html_cutoff_text', self.html_cutoff_text)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import datetime
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import unittest
|
||||
import uuid
|
||||
from decimal import ROUND_DOWN, ROUND_UP, Decimal
|
||||
|
@ -25,6 +26,13 @@ try:
|
|||
except ImportError:
|
||||
typings = False
|
||||
|
||||
if sys.version_info[0] < 3:
|
||||
# python 2
|
||||
import mock
|
||||
else:
|
||||
# python 3
|
||||
from unittest import mock
|
||||
|
||||
|
||||
# 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):
|
||||
"""
|
||||
If `allow_blank=True` then '' is a valid input.
|
||||
|
|
Loading…
Reference in New Issue
Block a user