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)
| 10 | |
| 11 | class 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): |