Created
February 18, 2013 20:40
-
-
Save rweeks/4980509 to your computer and use it in GitHub Desktop.
Shows mongoengine tuple->list conversion
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
import unittest | |
from mongoengine.base import BaseField | |
from mongoengine.document import Document | |
from mongoengine.fields import ListField | |
from test import connect, disconnect | |
class EnumField(BaseField): | |
def __init__(self, **kwargs): | |
super(EnumField,self).__init__(**kwargs) | |
def to_mongo(self, value): | |
return value | |
def to_python(self, value): | |
return tuple(value) | |
class TestDoc(Document): | |
items = ListField(EnumField()) | |
class TestMongoEngine(unittest.TestCase): | |
def setUp(self): | |
connect() | |
TestDoc.drop_collection() | |
def tearDown(self): | |
disconnect() | |
def test_tuple_in_list(self): | |
tuples = [(100,'Testing')] | |
doc = TestDoc() | |
doc.items = tuples | |
doc.save() | |
x = TestDoc.objects().get() | |
assert x is not None | |
assert len(x.items) == 1 | |
assert tuple(x.items[0]) in tuples | |
assert x.items[0] in tuples # fails at this line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment