Esempio n. 1
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
Esempio n. 2
0
    def setUp(self):
        Mapper._mapper_by_classname.clear()
        self.datastore = create_datastore('mim:///test_db')
        self.doc_session = Session(self.datastore)
        self.odm_session = ODMSession(self.doc_session)

        class Base(MappedClass):
            class __mongometa__:
                name = 'test_doc'
                session = self.odm_session
                polymorphic_on = 'type'
                polymorphic_identity = 'base'

            _id = FieldProperty(S.ObjectId)
            type = FieldProperty(str, if_missing='base')
            a = FieldProperty(int)

        class Derived(Base):
            class __mongometa__:
                polymorphic_identity = 'derived'

            type = FieldProperty(str, if_missing='derived')
            b = FieldProperty(int)

        Mapper.compile_all()
        self.Base = Base
        self.Derived = Derived
Esempio n. 3
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
Esempio n. 4
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)
Esempio n. 5
0
 def setUp(self):
     self.datastore = create_datastore('mim:///test_db')
     session = Session(bind=self.datastore)
     self.session = ODMSession(session)
     basic = collection('basic', session)
     class Basic(object):
         pass
     self.session.mapper(Basic, basic)
     self.basic = basic
     self.Basic = Basic
Esempio n. 6
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
Esempio n. 7
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        self.session = ThreadLocalODMSession(Session(bind=self.datastore))

        class Parent(MappedClass):
            class __mongometa__:
                name = 'parent'
                session = self.session

            _id = FieldProperty(S.ObjectId)

        Mapper.compile_all()
        self.Parent = Parent
        self.create_app = TestApp(MingMiddleware(self._wsgi_create_object))
        self.remove_app = TestApp(MingMiddleware(self._wsgi_remove_object))
        self.remove_exc = TestApp(MingMiddleware(self._wsgi_remove_object_exc))
Esempio n. 8
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')
Esempio n. 9
0
    def __init__(self):
        self.ming_session = Session()
        self.DBSession = ThreadLocalODMSession(self.ming_session)

        class User(MappedClass):
            class __mongometa__:
                session = self.DBSession
                name = 'tg_user'
                unique_indexes = [('user_name',), ('email_address',)]

            _id = FieldProperty(s.ObjectId)
            user_name = FieldProperty(s.String)
            email_address = FieldProperty(s.String)
            display_name = FieldProperty(s.String)
            password = FieldProperty(s.String)

        self.User = User
Esempio n. 10
0
    def setUp(self):
        self.datastore = create_datastore('mim:///test_db')
        self.session = ThreadLocalODMSession(Session(bind=self.datastore))

        class TestRelationParent(MappedClass):
            """This class _must_ have a unique class name or it will conflict
                with other tests."""
            class __mongometa__:
                name = 'parent'
                session = self.session

            _id = FieldProperty(S.ObjectId)

        Mapper.compile_all()
        self.Parent = TestRelationParent
        self.create_app = TestApp(MingMiddleware(self._wsgi_create_object))
        self.remove_app = TestApp(MingMiddleware(self._wsgi_remove_object))
        self.remove_exc = TestApp(MingMiddleware(self._wsgi_remove_object_exc))
Esempio n. 11
0
    def __init__(self):
        self.ming_session = Session()
        self.DBSession = ThreadLocalODMSession(self.ming_session)

        class User(MappedClass):
            class __mongometa__:
                session = self.DBSession
                name = 'tg_user'
                unique_indexes = [('user_name', ), ('email_address', )]

            _id = FieldProperty(s.ObjectId)
            user_name = FieldProperty(s.String)
            email_address = FieldProperty(s.String)
            display_name = FieldProperty(s.String)
            password = FieldProperty(s.String)

            @classmethod
            def by_user_name(cls, user_name):
                return cls.query.find({'user_name': user_name}).one()

        self.User = User
Esempio n. 12
0
    def setupClass(cls):
        if ming is None:
            raise SkipTest('Ming not available...')

        cls.basic_session = Session(create_datastore('mim:///'))
        cls.s = ODMSession(cls.basic_session)

        class Author(MappedClass):
            class __mongometa__:
                session = cls.s
                name = 'wiki_author'

            _id = FieldProperty(schema.ObjectId)
            name = FieldProperty(str)
            pages = RelationProperty('WikiPage')

        class WikiPage(MappedClass):
            class __mongometa__:
                session = cls.s
                name = 'wiki_page'

            _id = FieldProperty(schema.ObjectId)
            title = FieldProperty(str)
            text = FieldProperty(str)
            order = FieldProperty(int)
            author_id = ForeignIdProperty(Author)
            author = RelationProperty(Author)

        cls.Author = Author
        cls.WikiPage = WikiPage
        Mapper.compile_all()

        cls.author = Author(name='author1')
        author2 = Author(name='author2')

        WikiPage(title='Hello', text='Text', order=1, author=cls.author)
        WikiPage(title='Another', text='Text', order=2, author=cls.author)
        WikiPage(title='ThirdOne', text='Text', order=3, author=author2)
        cls.s.flush()
        cls.s.clear()
Esempio n. 13
0
def connect():
    session = Session(
        create_datastore(
            'mongodb://*****:*****@45.79.153.82:3431/portfoliodb'
        ))
    return session
Esempio n. 14
0
 def setUp(self):
     self.ds = create_datastore('mim:///test')
     self.Session = Session(bind=self.ds)
     self.TestFS = fs.filesystem('test_fs', self.Session)
Esempio n. 15
0
import ming
from ming.datastore import create_datastore
from ming import Session
from ming import schema as s
from ming.odm import ThreadLocalORMSession, FieldProperty, Mapper
from ming.odm.declarative import MappedClass
from datetime import datetime

mainsession = Session()
DBSession = ThreadLocalORMSession(mainsession)

database_setup = False
bind = None


def setup_database():
    global bind, database_setup
    if not database_setup:
        bind = create_datastore('mim:///test')
        mainsession.bind = bind
        ming.odm.Mapper.compile_all()
        database_setup = True


def clear_database():
    global engine, database_setup
    if not database_setup:
        setup_database()


class Thing(MappedClass):
Esempio n. 16
0
from ming.datastore import DataStore
from ming import Session

bind = DataStore('mongodb://localhost:27017/test_database')
session = Session(bind)

from ming import Field, Document, schema
import datetime


class WikiPage(Document):
    class __mongometa__:
        session = session
        name = 'pages'

    _id = Field(schema.ObjectId)
    author = Field(str)
    title = Field(str)
    tags = Field([str])
    date = Field(datetime.datetime)
    text = Field(str)


page = WikiPage.m.find().one()

page

page.author = 'Rick'

page.m.save()
Esempio n. 17
0
 class __mongometa__:
     name = '_flyway_migration_info'
     session = Session()
Esempio n. 18
0
from ming import collection, Field, Session
from ming import schema as S
from ming.declarative import Document

session = Session()
"""
Champion = collection(
    'champion.name', session,
    Field('_id', S.ObjectId),
    Field('name', str)
)
"""
class Champion(Document):
    class __mongometa__:
        session=session
        name='champion.name'
        indexes=['champion.name']
    _id=Field(str)
    name=Field(str)
    data=Field([
Esempio n. 19
0
#{initial-imports
from ming import Session
from ming.datastore import DataStore
from ming.odm import ThreadLocalODMSession

bind = DataStore('mongodb://localhost:27017/', database='odm_tutorial')
doc_session = Session(bind)
session = ThreadLocalODMSession(doc_session=doc_session)
#}

#{odm-imports
from ming import schema
from ming.odm import FieldProperty, ForeignIdProperty, RelationProperty
from ming.odm import Mapper
from ming.odm.declarative import MappedClass
#}

class WikiPage(MappedClass):
    
    class __mongometa__:
        session = session
        name = 'wiki_page'

    _id = FieldProperty(schema.ObjectId)
    title = FieldProperty(str)
    text = FieldProperty(str)

    comments=RelationProperty('WikiComment')

class WikiComment(MappedClass):
Esempio n. 20
0
from datetime import datetime

from pymongo import MongoClient
from ming import Session, Field, schema, create_datastore
from ming.declarative import Document

session = Session(create_datastore('mongodb://localhost:27017/echo'))

db = MongoClient().echo


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)


class Post(Document):
    class __mongometa__:
        session = session
        name = 'post'

    _id = Field(schema.ObjectId)
    created = Field(datetime)
    text = Field(str)