forked from MongoEngine/mongoengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for issue MongoEngine#904, also includes a test which checks the …
…error case I reported in the issue report.
- Loading branch information
Showing
2 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# -*- coding: utf-8 -*- | ||
import sys | ||
sys.path[0:0] = [""] | ||
import unittest | ||
from mongoengine import * | ||
|
||
__all__ = ("DbFieldParameterTest", ) | ||
|
||
|
||
class DbFieldParameterTest(unittest.TestCase): | ||
|
||
def test_document_db_field_validation(self): | ||
|
||
# https://github.com/MongoEngine/mongoengine/issues/904 | ||
|
||
data = {'b': {'c': [{'x': 1.0, 'y': 2.0}]}} | ||
|
||
class C(EmbeddedDocument): | ||
x = FloatField(db_field='fx') | ||
y = FloatField(db_field='fy') | ||
|
||
class B(EmbeddedDocument): | ||
c = ListField(EmbeddedDocumentField(C), db_field='fc') | ||
|
||
class A(Document): | ||
b = EmbeddedDocumentField(B, db_field='fb') | ||
|
||
a = A(**data) | ||
|
||
try: | ||
a.validate() | ||
except ValidationError as e: | ||
self.fail("ValidationError raised: %s" % e.message) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |