|
2 | 2 | import warnings
|
3 | 3 |
|
4 | 4 | import pytest
|
| 5 | +from django.db import models |
5 | 6 | from django.test import RequestFactory, TestCase, override_settings
|
6 | 7 | from django.urls import path
|
7 | 8 | from django.utils.translation import gettext_lazy as _
|
@@ -110,6 +111,24 @@ class Serializer(serializers.Serializer):
|
110 | 111 | assert data['properties']['default_false']['default'] is False, "default must be false"
|
111 | 112 | assert 'default' not in data['properties']['without_default'], "default must not be defined"
|
112 | 113 |
|
| 114 | + def test_nullable_fields(self): |
| 115 | + class Model(models.Model): |
| 116 | + rw_field = models.CharField(null=True) |
| 117 | + ro_field = models.CharField(null=True) |
| 118 | + |
| 119 | + class Serializer(serializers.ModelSerializer): |
| 120 | + class Meta: |
| 121 | + model = Model |
| 122 | + fields = ["rw_field", "ro_field"] |
| 123 | + read_only_fields = ["ro_field"] |
| 124 | + |
| 125 | + inspector = AutoSchema() |
| 126 | + |
| 127 | + data = inspector.map_serializer(Serializer()) |
| 128 | + assert data['properties']['rw_field']['nullable'], "rw_field nullable must be true" |
| 129 | + assert data['properties']['ro_field']['nullable'], "ro_field nullable must be true" |
| 130 | + assert data['properties']['ro_field']['readOnly'], "ro_field read_only must be true" |
| 131 | + |
113 | 132 |
|
114 | 133 | @pytest.mark.skipif(uritemplate is None, reason='uritemplate not installed.')
|
115 | 134 | class TestOperationIntrospection(TestCase):
|
|
0 commit comments