Add ability for dict keys to have . or $ in MongoDB >= 3.6
Starting in MongoDB >= 3.6, it is valid for dictionary keys to have $ or . in them as long as they don't start with $. Additional tests added.
This commit is contained in:
		| @@ -3,6 +3,7 @@ import pytest | ||||
|  | ||||
| from mongoengine import * | ||||
| from mongoengine.base import BaseDict | ||||
| from mongoengine.mongodb_support import MONGODB_36, get_mongodb_version | ||||
|  | ||||
| from tests.utils import MongoDBTestCase, get_as_pymongo | ||||
|  | ||||
| @@ -43,11 +44,7 @@ class TestDictField(MongoDBTestCase): | ||||
|         with pytest.raises(ValidationError): | ||||
|             post.validate() | ||||
|  | ||||
|         post.info = {"the.title": "test"} | ||||
|         with pytest.raises(ValidationError): | ||||
|             post.validate() | ||||
|  | ||||
|         post.info = {"nested": {"the.title": "test"}} | ||||
|         post.info = {"$title.test": "test"} | ||||
|         with pytest.raises(ValidationError): | ||||
|             post.validate() | ||||
|  | ||||
| @@ -55,6 +52,20 @@ class TestDictField(MongoDBTestCase): | ||||
|         with pytest.raises(ValidationError): | ||||
|             post.validate() | ||||
|  | ||||
|         post.info = {"nested": {"the.title": "test"}} | ||||
|         if get_mongodb_version() < MONGODB_36: | ||||
|             with pytest.raises(ValidationError): | ||||
|                 post.validate() | ||||
|         else: | ||||
|             post.validate() | ||||
|  | ||||
|         post.info = {"dollar_and_dot": {"te$st.test": "test"}} | ||||
|         if get_mongodb_version() < MONGODB_36: | ||||
|             with pytest.raises(ValidationError): | ||||
|                 post.validate() | ||||
|         else: | ||||
|             post.validate() | ||||
|  | ||||
|         post.info = {"title": "test"} | ||||
|         post.save() | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user