File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 11
11
12
12
import pytest
13
13
14
+ from rest_framework .utils import json
15
+
14
16
try :
15
17
import pytz
16
18
except ImportError :
@@ -2193,7 +2195,30 @@ def test_against_partial_and_full_updates(self):
2193
2195
field .partial = False
2194
2196
assert field .get_value (QueryDict ("" )) == []
2195
2197
field .partial = True
2196
- assert field .get_value (QueryDict ('' )) == rest_framework .fields .empty
2198
+ assert field .get_value (QueryDict ("" )) == rest_framework .fields .empty
2199
+
2200
+ def test_valid_inputs_is_json_serializable (self ):
2201
+ for input_value , _ in get_items (self .valid_inputs ):
2202
+ validated = self .field .run_validation (input_value )
2203
+
2204
+ try :
2205
+ json .dumps (validated )
2206
+ except TypeError as e :
2207
+ assert (
2208
+ False
2209
+ ), f"Validated output not JSON serializable: { repr (validated )} ; Error: { e } "
2210
+
2211
+ def test_output_is_json_serializable (self ):
2212
+ for output_value , _ in get_items (self .outputs ):
2213
+ representation = self .field .to_representation (output_value )
2214
+
2215
+ try :
2216
+ json .dumps (representation )
2217
+ except TypeError as e :
2218
+ assert False , (
2219
+ f"to_representation output not JSON serializable: "
2220
+ f"{ repr (representation )} ; Error: { e } "
2221
+ )
2197
2222
2198
2223
2199
2224
class TestEmptyMultipleChoiceField (FieldValues ):
You can’t perform that action at this time.
0 commit comments