File tree 1 file changed +32
-0
lines changed
1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -87,3 +87,35 @@ def test_render_format_keys(settings):
87
87
88
88
result = json .loads (rendered .decode ())
89
89
assert result ['data' ]['attributes' ]['json-field' ] == {'json-key' : 'JsonValue' }
90
+
91
+
92
+ def test_writeonly_not_in_response (settings ):
93
+ """Test that writeonly fields are not shown in list response"""
94
+
95
+ settings .JSON_API_FORMAT_FIELD_NAMES = 'dasherize'
96
+
97
+ class WriteonlyTestSerializer (serializers .ModelSerializer ):
98
+ '''Serializer for testing the absence of write_only fields'''
99
+ comments = serializers .ResourceRelatedField (
100
+ many = True ,
101
+ write_only = True ,
102
+ queryset = Comment .objects .all ()
103
+ )
104
+
105
+ rating = serializers .IntegerField (write_only = True )
106
+
107
+ class Meta :
108
+ model = Entry
109
+ fields = ('comments' , 'rating' )
110
+
111
+ class WriteOnlyDummyTestViewSet (views .ReadOnlyModelViewSet ):
112
+ queryset = Entry .objects .all ()
113
+ serializer_class = WriteonlyTestSerializer
114
+
115
+
116
+ rendered = render_dummy_test_serialized_view (WriteOnlyDummyTestViewSet )
117
+
118
+ result = json .loads (rendered .decode ())
119
+
120
+ assert 'rating' not in result ['data' ]['attributes' ]
121
+ assert 'relationships' not in result ['data' ]
You can’t perform that action at this time.
0 commit comments