Permalink
Browse files

[allura🎟#4603] Get ming tests running with new syntax for create_engi…

…ne/create_datastore (except flyway)

Signed-off-by: Rick Copeland <rick@arborian.com>
  • Loading branch information...
1 parent 622f0cb commit 6bd952d44dab84b9354d88e422ea766014c00747 @rick446 rick446 committed Jul 25, 2012
Showing with 28 additions and 21 deletions.
  1. +2 −2 flyway/command.py
  2. +11 −7 ming/datastore.py
  3. +6 −2 ming/tests/test_datastore.py
  4. +3 −3 ming/tests/test_gridfs.py
  5. +2 −3 ming/tests/test_middleware.py
  6. +4 −4 ming/tests/test_mim.py
View
@@ -33,11 +33,11 @@ def command(self):
bind = create_engine(self.options.connection_url)
if self.options.database is None:
datastores = [
- create_datastore(bind=bind, database=db)
+ create_datastore(db, bind=bind)
for db in bind.conn.database_names()
if db not in ('admin', 'local') ]
else:
- datastores = [ create_datastore(bind=bind, database=self.options.database) ]
+ datastores = [ create_datastore(self.options.database, bind=bind) ]
for ds in datastores:
self.log.info('Migrate DB: %s', ds.database)
if self.options.status_only:
View
@@ -30,7 +30,7 @@ def create_engine(*args, **kwargs):
connect_retry = kwargs.pop('connect_retry', 3)
sleep = kwargs.pop('sleep', None)
if use_class is None:
- if args and args[0].startswith('mim://'):
+ if args and args[0].startswith('mim:'):
use_class = mim.Connection
args = args[1:]
elif 'replicaSet' in kwargs:
@@ -134,12 +134,16 @@ def __repr__(self): # pragma no cover
return '<Engine %r>' % self._conn
def __getattr__(self, name):
- if self._conn is None: self.connect()
- return getattr(self._conn, name)
+ if name == 'conn': raise AttributeError, name
+ return getattr(self.conn, name)
def __getitem__(self, name):
+ return self.conn[name]
+
+ @property
+ def conn(self):
if self._conn is None: self.connect()
- return self._conn[name]
+ return self._conn
def connect(self):
for x in xrange(self._connect_retry):
@@ -160,7 +164,7 @@ def connect(self):
class DataStore(object):
def __init__(self, bind, name, authenticate=None):
- self._bind = bind
+ self.bind = bind
self.name = name
self._authenticate = authenticate
self._db = None
@@ -180,8 +184,8 @@ def conn(self):
@property
def db(self):
if self._db is None:
- if self._bind is None: raise AttributeError
- self._db = self._bind[self.name]
+ if self.bind is None: raise AttributeError
+ self._db = self.bind[self.name]
if self._authenticate:
self._db.authenticate(**self._authenticate)
return self._db
@@ -4,10 +4,10 @@
from pymongo.errors import ConnectionFailure
import ming
-from ming import Session, Field, Document
+from ming import Session
+from ming import mim
from ming import create_datastore, create_engine
from ming.datastore import Engine
-from ming import schema as S
class DummyConnection(object):
def __init__(*args, **kwargs): pass
@@ -152,6 +152,10 @@ def test_no_double_auth(self):
'mongodb://user:pass@server/test_db',
authenticate=dict(name='user', password='pass'))
+ def test_mim_ds(self):
+ ds = create_datastore('mim:///test_db')
+ assert isinstance(ds.bind.connect(), mim.Connection)
+
def _check_datastore(self, ds, db_name):
assert ds.db is self.MockConn()[db_name]
assert ds.name == db_name
@@ -8,7 +8,7 @@
import mock
-from ming import datastore
+from ming import create_datastore
from ming import fs, Session
def mock_datastore():
@@ -24,13 +24,13 @@ def mock_collection():
class TestFS(TestCase):
def setUp(self):
- self.ds = datastore.DataStore('mim:///', database='test')
+ self.ds = create_datastore('mim:///test')
self.Session = Session(bind=self.ds)
self.TestFS = fs.filesystem(
'test_fs', self.Session)
def tearDown(self):
- self.ds.bind.conn.drop_all()
+ self.ds.bind.drop_all()
def test_simple(self):
with self.TestFS.m.new_file('test.txt') as fp:
@@ -4,7 +4,7 @@
from webob import exc
from ming import schema as S
-from ming import datastore as DS
+from ming import create_datastore
from ming import Session
from ming.odm import ThreadLocalODMSession
from ming.odm import FieldProperty, Mapper
@@ -14,8 +14,7 @@
class TestRelation(TestCase):
def setUp(self):
- self.datastore = DS.DataStore(
- 'mim:///', database='test_db')
+ self.datastore = create_datastore('mim:///test_db')
self.session = ThreadLocalODMSession(Session(bind=self.datastore))
class Parent(MappedClass):
class __mongometa__:
View
@@ -1,11 +1,11 @@
from unittest import TestCase
-from ming import datastore as DS
+from ming import create_datastore
class TestDatastore(TestCase):
def setUp(self):
- self.bind = DS.DataStore(master='mim:///', database='testdb')
+ self.bind = create_datastore('mim:///testdb')
self.bind.conn.drop_all()
self.bind.db.coll.insert({'_id':'foo', 'a':2, 'c':[1,2,3]})
@@ -38,7 +38,7 @@ class TestCommands(TestCase):
return total; }'''
def setUp(self):
- self.bind = DS.DataStore(master='mim:///', database='testdb')
+ self.bind = create_datastore('mim:///testdb')
self.bind.conn.drop_all()
self.doc = {'_id':'foo', 'a':2, 'c':[1,2,3]}
self.bind.db.coll.insert(self.doc)
@@ -114,7 +114,7 @@ def test_mr_reduce(self):
class TestCollection(TestCase):
def setUp(self):
- self.bind = DS.DataStore(master='mim:///', database='testdb')
+ self.bind = create_datastore('mim:///testdb')
self.bind.conn.drop_all()
def test_upsert_simple(self):

0 comments on commit 6bd952d

Please sign in to comment.