Ejemplo n.º 1
0
        class Doc(Document):
            class __mongometa__:
                name = 'coll'
                session = self.session

            _id = Field(str)
            a = Field(int)
Ejemplo n.º 2
0
 def test_enable_instrument(self):
     session = Session(bind=self.datastore)
     basic1 = collection(
         'basic1', session,
         Field('_id', S.ObjectId),
         Field('a', int),
         Field('b', [int]),
         Field('c', dict(
                 d=int, e=int)))
     class Basic1(object):
         pass
     self.session.mapper(Basic1, basic1, options=dict(instrument=False))
     # Put a doc in the DB
     Basic1(a=1, b=[2,3], c=dict(d=4, e=5))
     self.session.flush()
     # Load back with instrumentation
     self.session.clear()
     obj = Basic1.query.find().options(instrument=True).first()
     self.assertEqual(type(obj.b), InstrumentedList)
     self.assertEqual(type(obj.c), InstrumentedObj)
     # Load back without instrumentation
     self.session.clear()
     obj = Basic1.query.find().options(instrument=False).first()
     self.assertEqual(type(obj.b), list)
     self.assertEqual(type(obj.c), Object)
Ejemplo n.º 3
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        session = Session(bind=self.datastore)
        self.session = ODMSession(session)
        base = collection('test_doc',
                          session,
                          Field('_id', S.ObjectId),
                          Field('type', str, if_missing='base'),
                          Field('a', int),
                          polymorphic_on='type',
                          polymorphic_identity='base')
        derived = collection(base,
                             Field('type', str, if_missing='derived'),
                             Field('b', int),
                             polymorphic_identity='derived')

        class Base(object):
            pass

        class Derived(Base):
            pass

        mapper(Base, base, self.session)
        mapper(Derived, derived, self.session)
        self.Base = Base
        self.Derived = Derived
Ejemplo n.º 4
0
    def setUp(self):
        class IteratorMock(mock.Mock):
            def __init__(self, base_iter):
                super().__init__()
                self._base_iter = base_iter

            def __iter__(self):
                return self

            def next(self):
                return next(self._base_iter)

            __next__ = next

        self.MockSession = mock.Mock()
        self.MockSession.db = mock.MagicMock()
        self.TestDoc = collection('test_doc', self.MockSession,
                                  Field('a', int), Field('b', dict(a=int)))

        mongo_cursor = IteratorMock(iter([{}, {}, {}]))
        mongo_cursor.count = mock.Mock(return_value=3)
        mongo_cursor.limit = mock.Mock(return_value=mongo_cursor)
        mongo_cursor.hint = mock.Mock(return_value=mongo_cursor)
        mongo_cursor.skip = mock.Mock(return_value=mongo_cursor)
        mongo_cursor.sort = mock.Mock(return_value=mongo_cursor)
        self.cursor = Cursor(self.TestDoc, mongo_cursor)
Ejemplo n.º 5
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        session = Session(bind=self.datastore)
        self.session = ODMSession(session)

        class Parent(object):
            pass

        class Child(object):
            pass

        parent = collection('parent', session, Field('_id', int))
        child = collection('child', session, Field('_id', int),
                           Field('parent_id', int))
        mapper(Parent,
               parent,
               self.session,
               properties=dict(children=RelationProperty(Child)))
        mapper(Child,
               child,
               self.session,
               properties=dict(parent_id=ForeignIdProperty(Parent),
                               parent=RelationProperty(Parent)))
        self.Parent = Parent
        self.Child = Child
Ejemplo n.º 6
0
class MigrationInfo(Document):
    class __mongometa__:
        name = '_flyway_migration_info'
        session = Session()

    _id = Field(S.ObjectId)
    versions = Field({str: int})
Ejemplo n.º 7
0
    def test_index_inheritance_neither(self):
        NoIndexDoc = collection('test123', self.MockSession,
                                Field('_id', S.ObjectId), Field('test1', str),
                                Field('test2', str), Field('test3', str))
        StillNone = collection(NoIndexDoc)

        self.assertEqual(list(StillNone.m.indexes), [])
Ejemplo n.º 8
0
 def setUp(self):
     self.MockSession = mock.Mock()
     self.MockSession.db = mock.MagicMock()
     self.TestDoc = collection(
         'test_doc', self.MockSession,
         Field('a', int, if_missing=None, index=True),
         Field('b', S.Object, if_missing=dict(a=S.Int(if_missing=None))))
     self.TestDocNoSchema = collection('test_doc', self.MockSession)
Ejemplo n.º 9
0
 def setUp(self):
     self.MockSession = mock.Mock()
     self.MockSession.db = mock.MagicMock()
     self.MyDoc = collection(
         'test_some_indexes', self.MockSession, Field('_id', S.ObjectId),
         Field('test1', str, index=True, unique=True), Field('test2'),
         Field('test3', str), Index('test2'),
         Index('test1', 'test2', direction=pymongo.DESCENDING))
Ejemplo n.º 10
0
class Learning(Document):
    class __mongometa__:
        session = connection.connection
        name = 'learnings'

    _id = Field(schema.ObjectId)
    skill = Field(schema.String)
    progress = Field(schema.String)
Ejemplo n.º 11
0
 class __mongometa__:
     session = Session.by_name(_get_dataobj_id())
     name = 'classification_modes'
     _id = Field(schema.ObjectId)
     mode_type = Field(str)
     maxalleles = Field(int)
     num_modes = Field(int)
     boundary_map = Field([mode_boundary])
Ejemplo n.º 12
0
class Blurb(Document):
    class __mongometa__:
        session = connection.connection
        name = 'blurbs'

    _id = Field(schema.ObjectId)
    user = Field(schema.String)
    blurb = Field(schema.String)
Ejemplo n.º 13
0
class Platform(Document):

    class __mongometa__:
        session = connection.connection
        name = 'platforms'

    _id = Field(schema.ObjectId)
    title = Field(schema.String)
    text = Field(schema.String)
Ejemplo n.º 14
0
class Skill(Document):
    class __mongometa__:
        session = connection.connection
        name = 'skills'

    _id = Field(schema.ObjectId)
    name = Field(schema.String)
    icon = Field(schema.String)
    type = Field(schema.String)
Ejemplo n.º 15
0
class Semaphore(Document):

    class __mongometa__:
        name = 'chapman.semaphore'
        session = doc_session

    _id = Field(str)
    value = Field(int)
    mq = Field([int])
Ejemplo n.º 16
0
class Institution(Document):
    class __mongometa__:
        session = connection.connection
        name = 'institutions'

    _id = Field(schema.ObjectId)
    name = Field(schema.String)
    image = Field(schema.String)
    location = Field(schema.String)
    type = Field(schema.String)
Ejemplo n.º 17
0
class Education(Document):
    class __mongometa__:
        session = connection.connection
        name = 'educations'

    _id = Field(schema.ObjectId)
    attended = Field(schema.String)
    institution = Field(schema.String)
    description = Field(schema.String)
    degree = Field(schema.String)
Ejemplo n.º 18
0
class Entry(Document):

    class __mongometa__:
        session = connection.connection
        name = 'entries'

    _id = Field(schema.ObjectId)
    user = Field(schema.String)
    date = Field(datetime, if_missing=datetime.utcnow)
    text = Field(schema.String)
Ejemplo n.º 19
0
class Subscription(Document):
    class __mongometa__:
        session = session
        name = 'subscription'

    _id = Field(schema.ObjectId)
    url = Field(str)
    keyword = Field(str)
    mail = Field(str)
    offset = Field(datetime)
Ejemplo n.º 20
0
class Post(Document):
    class __mongometa__:
        session = session
        name = 'post'

    _id = Field(schema.ObjectId)
    created = Field(datetime)
    text = Field(str)
    page = Field(str)
    link = Field(str)
Ejemplo n.º 21
0
 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))
Ejemplo n.º 22
0
    def test_index_inheritance_parent_none(self):
        NoIndexDoc = collection('test123', self.MockSession,
                                Field('_id', S.ObjectId), Field('test1', str),
                                Field('test2', str), Field('test3', str))
        AddSome = collection(NoIndexDoc, Index('foo'), Index('bar',
                                                             unique=True))

        self.assertEqual(
            list(AddSome.m.indexes),
            [Index('foo'), Index('bar', unique=True)])
Ejemplo n.º 23
0
class TaskState(Document):
    class __mongometa__:
        name = 'chapman.task'
        session = doc_session
        indexes = [
            [('parent_id', 1), ('data.composite_position', 1)],
        ]

    _id = Field(int, if_missing=lambda: getrandbits(63))
    type = Field(str)
    parent_id = Field(int, if_missing=None)
    status = Field(str, if_missing='pending')
    _result = Field('result', S.Binary)
    data = Field({str: None})
    options = Field(
        dict(
            queue=S.String(if_missing='chapman'),
            priority=S.Int(if_missing=10),
            immutable=S.Bool(if_missing=False),
            ignore_result=S.Bool(if_missing=False),
            semaphores=[str],
        ))
    on_complete = Field(int, if_missing=None)
    mq = Field([int])

    result = pickle_property('_result')

    @classmethod
    def set_result(cls, id, result):
        cls.m.update_partial(
            {'_id': id},
            {'$set': {
                'result': dumps(result),
                'status': result.status
            }})
Ejemplo n.º 24
0
class MyModel(Document):
    class __mongometa__:
        session = Session.by_name('default')
        name = 'my_model'

    _id = Field(schema.ObjectId)
    name = Field(str)
    value = Field(int)

    def __str__(self):
        return "<Model %s: %d>" % (self.name, self.value)
Ejemplo n.º 25
0
 def setUp(self):
     self.MockSession = mock.Mock()
     self.MockSession.db = mock.MagicMock()
     self.Base = collection('test_doc',
                            self.MockSession,
                            Field('type', str),
                            Field('a', int),
                            polymorphic_on='type',
                            polymorphic_identity='base')
     self.Derived = collection(self.Base,
                               Field('b', int),
                               polymorphic_identity='derived')
Ejemplo n.º 26
0
 def setUp(self):
     self.MockSession = mock.Mock()
     self.MockSession.db = mock.MagicMock()
     TestDoc_old = collection('test_doc', self.MockSession,
                              Field('version', 1), Field('a', int))
     self.TestDoc = collection(
         'test_doc',
         self.MockSession,
         Field('version', 2),
         Field('a', int),
         Field('b', int, required=True),
         version_of=TestDoc_old,
         migrate=lambda old_doc: dict(old_doc, b=42, version=2))
Ejemplo n.º 27
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        session = Session(bind=self.datastore)
        self.session = ODMSession(session)
        basic = collection('basic', session, Field('_id', S.ObjectId),
                           Field('a', int), Field('b', [int]),
                           Field('c', dict(d=int, e=int)))

        class Basic(object):
            pass

        self.session.mapper(Basic, basic)
        self.basic = basic
        self.Basic = Basic
Ejemplo n.º 28
0
class TraitCountSample(Document):
    class __mongometa__:
        session = Session.by_name(_get_dataobj_id())
        name = 'trait_count_sample'

    _id = Field(schema.ObjectId)
    simulation_time = Field(int)
    replication = Field(int)
    locus = Field(int)
    sample_size = Field(int)
    population_size = Field(int)
    mutation_rate = Field(float)
    simulation_run_id = Field(str)
    allele = Field(int)
    count = Field(float)
Ejemplo n.º 29
0
 def setUp(self):
     self.MockSession = mock.Mock()
     self.MockSession.db = mock.MagicMock()
     self.TestDoc = collection('test_doc', self.MockSession,
                               Field('a', int), Field('b', dict(a=int)))
     base_iter = iter([{}, {}, {}])
     mongo_cursor = mock.Mock()
     mongo_cursor.count = mock.Mock(return_value=3)
     mongo_cursor.__iter__ = lambda self: base_iter
     mongo_cursor.next = base_iter.next
     mongo_cursor.limit = mock.Mock(return_value=mongo_cursor)
     mongo_cursor.hint = mock.Mock(return_value=mongo_cursor)
     mongo_cursor.skip = mock.Mock(return_value=mongo_cursor)
     mongo_cursor.sort = mock.Mock(return_value=mongo_cursor)
     self.cursor = Cursor(self.TestDoc, mongo_cursor)
Ejemplo n.º 30
0
 def setUp(self):
     self.bind = mock_datastore()
     self.session = Session(self.bind)
     self.hooks_called = defaultdict(list)
     self.Base = collection('test_doc',
                            self.session,
                            Field('_id', int),
                            Field('type', str),
                            Field('a', int),
                            polymorphic_on='type',
                            polymorphic_identity='base',
                            before_save=lambda inst:
                            (self.hooks_called['before_save'].append(inst)))
     self.Derived = collection(self.Base,
                               Field('b', int),
                               polymorphic_identity='derived')