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 :
@@ -2082,7 +2084,30 @@ def test_against_partial_and_full_updates(self):
2082
2084
field .partial = False
2083
2085
assert field .get_value (QueryDict ('' )) == []
2084
2086
field .partial = True
2085
- assert field .get_value (QueryDict ('' )) == rest_framework .fields .empty
2087
+ assert field .get_value (QueryDict ("" )) == rest_framework .fields .empty
2088
+
2089
+ def test_valid_inputs_is_json_serializable (self ):
2090
+ for input_value , _ in get_items (self .valid_inputs ):
2091
+ validated = self .field .run_validation (input_value )
2092
+
2093
+ try :
2094
+ json .dumps (validated )
2095
+ except TypeError as e :
2096
+ assert (
2097
+ False
2098
+ ), f"Validated output not JSON serializable: { repr (validated )} ; Error: { e } "
2099
+
2100
+ def test_output_is_json_serializable (self ):
2101
+ for output_value , _ in get_items (self .outputs ):
2102
+ representation = self .field .to_representation (output_value )
2103
+
2104
+ try :
2105
+ json .dumps (representation )
2106
+ except TypeError as e :
2107
+ assert False , (
2108
+ f"to_representation output not JSON serializable: "
2109
+ f"{ repr (representation )} ; Error: { e } "
2110
+ )
2086
2111
2087
2112
2088
2113
class TestEmptyMultipleChoiceField (FieldValues ):
You can’t perform that action at this time.
0 commit comments