@@ -100,6 +100,36 @@ def test_get_value_from_instance(self):
100
100
'last_name' : "bar" ,
101
101
})
102
102
103
+ def test_get_value_from_instance_with_partial_properties (self ):
104
+ field = ObjectField (
105
+ attr = 'person' ,
106
+ properties = {
107
+ 'first_name' : TextField (analyzer = 'foo' )
108
+ }
109
+ )
110
+
111
+ instance = NonCallableMock (
112
+ person = NonCallableMock (first_name = 'foo' , last_name = 'bar' )
113
+ )
114
+
115
+ self .assertEqual (field .get_value_from_instance (instance ), {
116
+ 'first_name' : "foo"
117
+ })
118
+
119
+ def test_get_value_from_instance_without_properties (self ):
120
+ field = ObjectField (attr = 'person' )
121
+
122
+ instance = NonCallableMock (
123
+ person = {'first_name' : 'foo' , 'last_name' : 'bar' }
124
+ )
125
+
126
+ self .assertEqual (field .get_value_from_instance (instance ),
127
+ {
128
+ 'first_name' : "foo" ,
129
+ 'last_name' : "bar"
130
+ }
131
+ )
132
+
103
133
def test_get_value_from_instance_with_inner_objectfield (self ):
104
134
field = ObjectField (attr = 'person' , properties = {
105
135
'first_name' : TextField (analyzer = 'foo' ),
@@ -120,6 +150,30 @@ def test_get_value_from_instance_with_inner_objectfield(self):
120
150
'additional' : {'age' : 12 }
121
151
})
122
152
153
+ def test_get_value_from_instance_with_inner_objectfield_without_properties (self ):
154
+ field = ObjectField (
155
+ attr = 'person' ,
156
+ properties = {
157
+ 'first_name' : TextField (analyzer = 'foo' ),
158
+ 'last_name' : TextField (),
159
+ 'additional' : ObjectField ()
160
+ }
161
+ )
162
+
163
+ instance = NonCallableMock (person = NonCallableMock (
164
+ first_name = "foo" ,
165
+ last_name = "bar" ,
166
+ additional = {'age' : 12 }
167
+ ))
168
+
169
+ self .assertEqual (field .get_value_from_instance (instance ),
170
+ {
171
+ 'first_name' : "foo" ,
172
+ 'last_name' : "bar" ,
173
+ 'additional' : {'age' : 12 }
174
+ }
175
+ )
176
+
123
177
def test_get_value_from_instance_with_none_inner_objectfield (self ):
124
178
field = ObjectField (attr = 'person' , properties = {
125
179
'first_name' : TextField (analyzer = 'foo' ),
@@ -168,6 +222,29 @@ def test_get_value_from_iterable(self):
168
222
}
169
223
])
170
224
225
+ def test_get_value_from_iterable_without_properties (self ):
226
+ field = ObjectField (attr = 'person' )
227
+
228
+ instance = NonCallableMock (
229
+ person = [
230
+ {'first_name' : "foo1" , 'last_name' : "bar1" },
231
+ {'first_name' : "foo2" , 'last_name' : "bar2" }
232
+ ]
233
+ )
234
+
235
+ self .assertEqual (field .get_value_from_instance (instance ),
236
+ [
237
+ {
238
+ 'first_name' : "foo1" ,
239
+ 'last_name' : "bar1" ,
240
+ },
241
+ {
242
+ 'first_name' : "foo2" ,
243
+ 'last_name' : "bar2" ,
244
+ }
245
+ ]
246
+ )
247
+
171
248
172
249
class NestedFieldTestCase (TestCase ):
173
250
def test_get_mapping (self ):
0 commit comments