MCPcopy Create free account
hub / github.com/MongoEngine/mongoengine / test_json_names

Method test_json_names

tests/document/test_json_serialisation.py:12–35  ·  view source on GitHub ↗

Going to test reported issue: https://github.com/MongoEngine/mongoengine/issues/654 where the reporter asks for the availability to perform a to_json with the original class names and not the abreviated mongodb document keys

(self)

Source from the content-addressed store, hash-verified

10
11class TestJson(MongoDBTestCase):
12 def test_json_names(self):
13 """
14 Going to test reported issue:
15 https://github.com/MongoEngine/mongoengine/issues/654
16 where the reporter asks for the availability to perform
17 a to_json with the original class names and not the abreviated
18 mongodb document keys
19 """
20
21 class Embedded(EmbeddedDocument):
22 string = StringField(db_field="s")
23
24 class Doc(Document):
25 string = StringField(db_field="s")
26 embedded = EmbeddedDocumentField(Embedded, db_field="e")
27
28 doc = Doc(string="Hello", embedded=Embedded(string="Inner Hello"))
29 doc_json = doc.to_json(
30 sort_keys=True, use_db_field=False, separators=(",", ":")
31 )
32
33 expected_json = """{"embedded":{"string":"Inner Hello"},"string":"Hello"}"""
34
35 assert doc_json == expected_json
36
37 def test_json_simple(self):
38 class Embedded(EmbeddedDocument):

Callers

nothing calls this directly

Calls 3

DocClass · 0.70
EmbeddedClass · 0.70
to_jsonMethod · 0.45

Tested by

no test coverage detected