Skip to content

Commit 34dc8b7

Browse files
one more unit test
1 parent f5ffbbc commit 34dc8b7

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

test_elasticsearch/test_dsl/test_field.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@
2424
from dateutil import tz
2525

2626
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+
)
2835

2936

3037
def test_date_range_deserialization() -> None:
@@ -235,6 +242,33 @@ class Inner(InnerDoc):
235242
field.Object(doc_class=Inner, dynamic=False)
236243

237244

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+
238272
def test_all_fields_exported() -> None:
239273
"""Make sure that all the generated field classes are exported at the top-level"""
240274
fields = [

0 commit comments

Comments
 (0)