@@ -29,6 +29,37 @@ def test_marshal(self):
29
29
assert not isinstance (output , OrderedDict )
30
30
assert output == {'foo' : 'bar' }
31
31
32
+ def test_marshal_wildcard_nested (self ):
33
+ nest = fields .Nested (OrderedDict ([('thumbnail' , fields .String ), ('video' , fields .String )]))
34
+ wild = fields .Wildcard (nest )
35
+ wildcard_fields = OrderedDict ([('*' , wild )])
36
+ model = OrderedDict ([('preview' , fields .Nested (wildcard_fields ))])
37
+ sub_dict = OrderedDict ([
38
+ ('9:16' , {'thumbnail' : 24 , 'video' : 12 }),
39
+ ('16:9' , {'thumbnail' : 25 , 'video' : 11 }),
40
+ ('1:1' , {'thumbnail' : 26 , 'video' : 10 })
41
+ ])
42
+ marshal_dict = OrderedDict ([('preview' , sub_dict )])
43
+ output = marshal (marshal_dict , model )
44
+ assert output == {'preview' : {'1:1' : {'thumbnail' : '26' , 'video' : '10' },
45
+ '16:9' : {'thumbnail' : '25' , 'video' : '11' },
46
+ '9:16' : {'thumbnail' : '24' , 'video' : '12' }}}
47
+
48
+ def test_marshal_wildcard_list (self ):
49
+ wild = fields .Wildcard (fields .List (fields .String ))
50
+ wildcard_fields = OrderedDict ([('*' , wild )])
51
+ model = OrderedDict ([('preview' , fields .Nested (wildcard_fields ))])
52
+ sub_dict = OrderedDict ([
53
+ ('1:1' , [1 , 2 , 3 ]),
54
+ ('16:9' , [4 , 5 , 6 ]),
55
+ ('9:16' , [7 , 8 , 9 ])
56
+ ])
57
+ marshal_dict = OrderedDict ([('preview' , sub_dict )])
58
+ output = marshal (marshal_dict , model )
59
+ assert output == {'preview' : {'9:16' : ['7' , '8' , '9' ],
60
+ '16:9' : ['4' , '5' , '6' ],
61
+ '1:1' : ['1' , '2' , '3' ]}}
62
+
32
63
def test_marshal_with_envelope (self ):
33
64
model = OrderedDict ([('foo' , fields .Raw )])
34
65
marshal_dict = OrderedDict ([('foo' , 'bar' ), ('bat' , 'baz' )])
0 commit comments