Skip to content

Commit 5cae556

Browse files
one more unit test
1 parent d6e025d commit 5cae556

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
@@ -23,7 +23,14 @@
2323
import pytest
2424
from dateutil import tz
2525

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+
)
2734

2835

2936
def test_date_range_deserialization() -> None:
@@ -232,3 +239,30 @@ class Inner(InnerDoc):
232239

233240
with pytest.raises(ValidationException):
234241
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

Comments
 (0)