@@ -98,6 +98,7 @@ class StringJsonAttributePerson(base):
98
98
# This model uses a String type for "json_tags" to avoid dependency on a nonstandard SQL type in testing, \
99
99
# while still demonstrating support
100
100
address = Column (MagicJSON )
101
+ tags = Column (MagicJSON )
101
102
102
103
yield StringJsonAttributePerson
103
104
@@ -136,7 +137,10 @@ class Computer(base):
136
137
137
138
138
139
@pytest .fixture (scope = "module" )
139
- def engine (person_tag_model , person_single_tag_model , person_model , computer_model , string_json_attribute_person_model ):
140
+ def engine (
141
+ person_tag_model , person_single_tag_model , person_model ,
142
+ computer_model , string_json_attribute_person_model
143
+ ):
140
144
engine = create_engine ("sqlite:///:memory:" )
141
145
person_tag_model .metadata .create_all (engine )
142
146
person_single_tag_model .metadata .create_all (engine )
@@ -245,6 +249,7 @@ class Meta:
245
249
name = fields .Str (required = True )
246
250
birth_date = fields .DateTime ()
247
251
address = fields .Nested (address_schema , many = False )
252
+ tags = fields .List (fields .Dict ())
248
253
249
254
yield StringJsonAttributePersonSchema
250
255
@@ -774,6 +779,35 @@ def test_post_list_nested(client, register_routes, computer):
774
779
assert response .status_code == 201
775
780
assert json .loads (response .get_data ())["data" ]["attributes" ]["tags" ][0 ]["key" ] == "k1"
776
781
782
+ def test_post_list_nested_field (client , register_routes ):
783
+ """
784
+ Test a schema contains a nested field is correctly serialized and deserialized
785
+ """
786
+ payload = {
787
+ 'data' : {
788
+ 'type' : 'string_json_attribute_person' ,
789
+ 'attributes' : {
790
+ 'name' : 'test' ,
791
+ 'tags' : [
792
+ {'key' : 'new_key' , 'value' : 'new_value' }
793
+ ],
794
+ },
795
+ }
796
+ }
797
+ with client :
798
+ response = client .post (
799
+ '/string_json_attribute_persons' ,
800
+ data = json .dumps (payload ),
801
+ content_type = 'application/vnd.api+json'
802
+ )
803
+ assert response .status_code == 201 , response .json ['errors' ]
804
+ assert json .loads (
805
+ response .get_data ()
806
+ )['data' ]['attributes' ]['tags' ][0 ]['key' ] == 'new_key'
807
+ assert json .loads (
808
+ response .get_data ()
809
+ )['data' ]['attributes' ]['tags' ][0 ]['value' ] == 'new_value'
810
+
777
811
778
812
def test_post_list_single (client , register_routes , person ):
779
813
payload = {
0 commit comments