|
1 | 1 | from unittest import mock
|
2 | 2 |
|
| 3 | +from django.db import models |
3 | 4 | from django.conf.urls import url
|
4 | 5 | from django.test import TestCase, override_settings
|
5 | 6 |
|
|
8 | 9 | from rest_framework.serializers import ModelSerializer
|
9 | 10 | from rest_framework.utils import json
|
10 | 11 | from rest_framework.utils.breadcrumbs import get_breadcrumbs
|
| 12 | +from rest_framework.utils.field_mapping import get_field_kwargs |
11 | 13 | from rest_framework.utils.formatting import lazy_format
|
12 | 14 | from rest_framework.utils.urls import remove_query_param, replace_query_param
|
13 | 15 | from rest_framework.views import APIView
|
@@ -267,3 +269,18 @@ def test_it_formats_lazily(self):
|
267 | 269 | assert message.format.call_count == 1
|
268 | 270 | str(formatted)
|
269 | 271 | assert message.format.call_count == 1
|
| 272 | + |
| 273 | + |
| 274 | +class GetFieldKwargsTest(TestCase): |
| 275 | + def test_get_text_field_kwargs(self): |
| 276 | + # TextField without choices |
| 277 | + f = models.TextField() |
| 278 | + kwargs = get_field_kwargs('f', f) |
| 279 | + assert 'style' in kwargs |
| 280 | + assert 'choices' not in kwargs |
| 281 | + |
| 282 | + # TextField with choices |
| 283 | + f = models.TextField(choices=['ONE', 'TWO']) |
| 284 | + kwargs = get_field_kwargs('f', f) |
| 285 | + assert 'style' not in kwargs |
| 286 | + assert 'choices' in kwargs |
0 commit comments