Exemple #1
0
    def setUp(self):
        from ming.session import Session
        self.bind = mock_datastore()
        self.session = Session(self.bind)
        self.hooks_called = defaultdict(list)
        tc = self

        class Base(Document):
            class __mongometa__:
                name = 'test_doc'
                session = self.session
                polymorphic_registry = {}
                polymorphic_on = 'type'
                polymorphic_identity = 'base'

                def before_save(instance):
                    tc.hooks_called['before_save'].append(instance)

            _id = Field(int)
            type = Field(str)
            a = Field(int)

        class Derived(Base):
            class __mongometa__:
                name = 'test_doc'
                session = self.session
                polymorphic_identity = 'derived'

            b = Field(int)

        self.Base = Base
        self.Derived = Derived
Exemple #2
0
    def setUp(self):
        self.bind = mock_datastore()
        self.session = Session(self.bind)

        class TestDoc(Document):
            class __mongometa__:
                name = 'test_doc'
                session = self.session
                indexes = [('b', 'c')]
                unique_indexes = [
                    ('cc'),
                ]

            _id = Field(S.ObjectId, if_missing=None)
            a = Field(S.Int, if_missing=None)
            b = Field(S.Object(dict(a=S.Int(if_missing=None))))
            cc = Field(dict(dd=int, ee=int))

        class TestDocNoSchema(Document):
            class __mongometa__:
                name = 'test_doc'
                session = self.session

        self.TestDoc = TestDoc
        self.TestDocNoSchema = TestDocNoSchema
Exemple #3
0
 class __mongometa__:
     session = Session()
     name = 'test123'
     schema = dict(
         _id=S.ObjectId,
         test1=str,
         test2=str,
         test3=int,
     )
Exemple #4
0
 def __init__(self, doc_session=None, bind=None, extensions=None):
     if doc_session is None:
         doc_session = Session(bind)
     if extensions is None: extensions = []
     self.impl = doc_session
     self.uow = UnitOfWork(self)
     self.imap = IdentityMap()
     self.extensions = [ e(self) for e in extensions ]
     self.autoflush = False
Exemple #5
0
 def testByName(self):
     session0 = Session.by_name("foo")
     session1 = Session.by_name("foo")
     self.assert_(session0 is session1)
Exemple #6
0
 def testByName(self):
     session0 = Session.by_name('foo')
     session1 = Session.by_name('foo')
     self.assertTrue(session0 is session1)