Skip to content

Instantly share code, notes, and snippets.

@rweeks
Created February 18, 2013 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rweeks/4980509 to your computer and use it in GitHub Desktop.
Save rweeks/4980509 to your computer and use it in GitHub Desktop.
Shows mongoengine tuple->list conversion
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