|
24 | 24 | from dateutil import tz |
25 | 25 |
|
26 | 26 | from elasticsearch import dsl |
27 | | -from elasticsearch.dsl import InnerDoc, Range, ValidationException, field |
| 27 | +from elasticsearch.dsl import ( |
| 28 | + AttrDict, |
| 29 | + AttrList, |
| 30 | + InnerDoc, |
| 31 | + Range, |
| 32 | + ValidationException, |
| 33 | + field, |
| 34 | +) |
28 | 35 |
|
29 | 36 |
|
30 | 37 | def test_date_range_deserialization() -> None: |
@@ -235,6 +242,33 @@ class Inner(InnerDoc): |
235 | 242 | field.Object(doc_class=Inner, dynamic=False) |
236 | 243 |
|
237 | 244 |
|
| 245 | +def test_dynamic_object() -> None: |
| 246 | + f = field.Object(dynamic=True) |
| 247 | + assert f.deserialize({"a": "b"}).to_dict() == {"a": "b"} |
| 248 | + assert f.deserialize(AttrDict({"a": "b"})).to_dict() == {"a": "b"} |
| 249 | + assert f.serialize({"a": "b"}) == {"a": "b"} |
| 250 | + assert f.serialize(AttrDict({"a": "b"})) == {"a": "b"} |
| 251 | + |
| 252 | + |
| 253 | +def test_dynamic_nested() -> None: |
| 254 | + f = field.Nested(dynamic=True) |
| 255 | + assert f.deserialize([{"a": "b"}, {"c": "d"}]) == [{"a": "b"}, {"c": "d"}] |
| 256 | + assert f.deserialize([AttrDict({"a": "b"}), {"c": "d"}]) == [ |
| 257 | + {"a": "b"}, |
| 258 | + {"c": "d"}, |
| 259 | + ] |
| 260 | + assert f.deserialize(AttrList([AttrDict({"a": "b"}), {"c": "d"}])) == [ |
| 261 | + {"a": "b"}, |
| 262 | + {"c": "d"}, |
| 263 | + ] |
| 264 | + assert f.serialize([{"a": "b"}, {"c": "d"}]) == [{"a": "b"}, {"c": "d"}] |
| 265 | + assert f.serialize([AttrDict({"a": "b"}), {"c": "d"}]) == [{"a": "b"}, {"c": "d"}] |
| 266 | + assert f.serialize(AttrList([AttrDict({"a": "b"}), {"c": "d"}])) == [ |
| 267 | + {"a": "b"}, |
| 268 | + {"c": "d"}, |
| 269 | + ] |
| 270 | + |
| 271 | + |
238 | 272 | def test_all_fields_exported() -> None: |
239 | 273 | """Make sure that all the generated field classes are exported at the top-level""" |
240 | 274 | fields = [ |
|
0 commit comments