|
23 | 23 | import pytest |
24 | 24 | from dateutil import tz |
25 | 25 |
|
26 | | -from elasticsearch.dsl import InnerDoc, Range, ValidationException, field |
| 26 | +from elasticsearch.dsl import ( |
| 27 | + AttrDict, |
| 28 | + AttrList, |
| 29 | + InnerDoc, |
| 30 | + Range, |
| 31 | + ValidationException, |
| 32 | + field, |
| 33 | +) |
27 | 34 |
|
28 | 35 |
|
29 | 36 | def test_date_range_deserialization() -> None: |
@@ -232,3 +239,30 @@ class Inner(InnerDoc): |
232 | 239 |
|
233 | 240 | with pytest.raises(ValidationException): |
234 | 241 | field.Object(doc_class=Inner, dynamic=False) |
| 242 | + |
| 243 | + |
| 244 | +def test_dynamic_object() -> None: |
| 245 | + f = field.Object(dynamic=True) |
| 246 | + assert f.deserialize({"a": "b"}).to_dict() == {"a": "b"} |
| 247 | + assert f.deserialize(AttrDict({"a": "b"})).to_dict() == {"a": "b"} |
| 248 | + assert f.serialize({"a": "b"}) == {"a": "b"} |
| 249 | + assert f.serialize(AttrDict({"a": "b"})) == {"a": "b"} |
| 250 | + |
| 251 | + |
| 252 | +def test_dynamic_nested() -> None: |
| 253 | + f = field.Nested(dynamic=True) |
| 254 | + assert f.deserialize([{"a": "b"}, {"c": "d"}]) == [{"a": "b"}, {"c": "d"}] |
| 255 | + assert f.deserialize([AttrDict({"a": "b"}), {"c": "d"}]) == [ |
| 256 | + {"a": "b"}, |
| 257 | + {"c": "d"}, |
| 258 | + ] |
| 259 | + assert f.deserialize(AttrList([AttrDict({"a": "b"}), {"c": "d"}])) == [ |
| 260 | + {"a": "b"}, |
| 261 | + {"c": "d"}, |
| 262 | + ] |
| 263 | + assert f.serialize([{"a": "b"}, {"c": "d"}]) == [{"a": "b"}, {"c": "d"}] |
| 264 | + assert f.serialize([AttrDict({"a": "b"}), {"c": "d"}]) == [{"a": "b"}, {"c": "d"}] |
| 265 | + assert f.serialize(AttrList([AttrDict({"a": "b"}), {"c": "d"}])) == [ |
| 266 | + {"a": "b"}, |
| 267 | + {"c": "d"}, |
| 268 | + ] |
0 commit comments