示例#1
0
 def setUp(self):
     M.doc_session.bind = ming.create_datastore(
         'test',
         bind=ming.create_engine(
             use_class=lambda *a, **kw: mim.Connection.get()))
     mim.Connection.get().clear_all()
     self.doubler = Function.decorate('double')(self._double)
示例#2
0
 def test_replica_set(self, MockConn):
     from pymongo import MongoClient
     result = create_engine(
         'mongodb://localhost:23,localhost:27017,localhost:999/',
         replicaSet='foo')
     conn = result.connect()
     assert isinstance(conn, MongoClient)
示例#3
0
 def command(self):
     self._setup_logging()
     self._load_migrations()
     from .runner import run_migration, reset_migration, show_status, set_status
     bind = create_engine(self.options.connection_url)
     if self.options.database is None:
         datastores = [
             create_datastore(db, bind=bind)
             for db in bind.conn.database_names()
             if db not in ('admin', 'local') ]
     else:
         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:
             show_status(ds)
         elif self.options.force:
             set_status(ds, self._target_versions())
         elif self.options.reset:
             reset_migration(ds, dry_run=self.options.dry_run)
         else:
             run_migration(ds, self._target_versions(), dry_run=self.options.dry_run)
         try:
             ds.conn.disconnect()
             ds._conn = None
         except: # MIM doesn't do this
             pass
示例#4
0
 def test_replica_set(self, MockConn):
     from pymongo import MongoClient
     result = create_engine(
         'mongodb://localhost:23,localhost:27017,localhost:999/',
         replicaSet='foo')
     conn = result.connect()
     assert isinstance(conn, MongoClient)
示例#5
0
 def test_with_connections(self, MockMasterSlaveConnection, MockConnection):
     from pymongo.master_slave_connection import MasterSlaveConnection
     master = Mock()
     slaves = [ Mock(), Mock() ]
     result = create_engine(master, slaves=slaves)
     conn = result.connect()
     assert isinstance(conn, MasterSlaveConnection)
     MockMasterSlaveConnection.assert_called_with(
         master, slaves,
         document_class=dict, tz_aware=False)
示例#6
0
 def test_with_strings(self, MockMasterSlaveConnection, MockConnection):
     from pymongo.master_slave_connection import MasterSlaveConnection
     result = create_engine(
         'master', slaves=['slave1', 'slave2'])
     conn = result.connect()
     assert isinstance(conn, MasterSlaveConnection)
     mock_conn = MockConnection()
     MockMasterSlaveConnection.assert_called_with(
         mock_conn, [mock_conn, mock_conn],
         document_class=dict, tz_aware=False)
示例#7
0
 def test_with_strings(self, MockMasterSlaveConnection, MockConnection):
     from pymongo.master_slave_connection import MasterSlaveConnection
     result = create_engine('master', slaves=['slave1', 'slave2'])
     conn = result.connect()
     assert isinstance(conn, MasterSlaveConnection)
     mock_conn = MockConnection()
     MockMasterSlaveConnection.assert_called_with(mock_conn,
                                                  [mock_conn, mock_conn],
                                                  document_class=dict,
                                                  tz_aware=False)
示例#8
0
 def test_with_connections(self, MockMasterSlaveConnection, MockConnection):
     from pymongo.master_slave_connection import MasterSlaveConnection
     master = Mock()
     slaves = [Mock(), Mock()]
     result = create_engine(master, slaves=slaves)
     conn = result.connect()
     assert isinstance(conn, MasterSlaveConnection)
     MockMasterSlaveConnection.assert_called_with(master,
                                                  slaves,
                                                  document_class=dict,
                                                  tz_aware=False)
示例#9
0
 def test_create_datastore_bind_not_allowed(self):
     self.assertRaises(ming.exc.MingConfigError,
                       create_datastore,
                       'mim://test_db',
                       bind=create_engine('master'))
示例#10
0
 def test_greenlets(self, gevent, MockConnection):
     from pymongo import MongoClient
     result = create_engine('master', use_greenlets=True)
     conn = result.connect()
     assert isinstance(conn, MongoClient)
示例#11
0
 def test_engine_with_name(self):
     self._check_datastore(
         create_datastore('test_db', bind=create_engine('master')),
         'test_db')
示例#12
0
 def test_get_db(self, MockConnection):
     from pymongo import MongoClient
     result = create_engine('master')
     conn = result.connect()
     assert isinstance(conn, MongoClient)
     self.assertEqual(conn.read_preference, result.read_preference)
示例#13
0
 def test_normal(self, MockConnection):
     from pymongo import MongoClient
     result = create_engine('master')
     conn = result.connect()
     assert isinstance(conn, MongoClient)
示例#14
0
 def test_no_kwargs_with_bind(self):
     self.assertRaises(
         ming.exc.MingConfigError,
         create_datastore,
         'test_db', bind=create_engine('master'), replicaSet='foo')
示例#15
0
 def setUp(self):
     M.doc_session.bind = ming.create_datastore(
         'test', bind=ming.create_engine(
             use_class=lambda *a,**kw: mim.Connection.get()))
     mim.Connection.get().clear_all()
     self.doubler = Function.decorate('double')(self._double)
示例#16
0
 def test_no_kwargs_with_bind(self):
     self.assertRaises(
         ming.exc.MingConfigError,
         create_datastore,
         'test_db', bind=create_engine('master'), replicaSet='foo')
示例#17
0
 def test_normal(self, MockConnection):
     from pymongo import MongoClient
     result = create_engine('master')
     conn = result.connect()
     assert isinstance(conn, MongoClient)
示例#18
0
 def test_get_db(self, MockConnection):
     from pymongo import MongoClient
     result = create_engine('master')
     conn = result.connect()
     assert isinstance(conn, MongoClient)
     self.assertEqual(conn.read_preference, result.read_preference)
示例#19
0
 def test_mim(self):
     with patch('ming.datastore.mim.Connection', spec=True) as Connection:
         result = create_engine('mim:///')
         conn = result.connect()
         assert conn is Connection.get()
示例#20
0
 def test_greenlets(self, gevent, MockConnection):
     from pymongo import MongoClient
     result = create_engine('master', use_greenlets=True)
     conn = result.connect()
     assert isinstance(conn, MongoClient)
示例#21
0
 def test_engine_with_name(self):
     self._check_datastore(
         create_datastore('test_db', bind=create_engine('master')),
         'test_db')
示例#22
0
 def test_mim(self):
     with patch('ming.datastore.mim.Connection', spec=True) as Connection:
         result = create_engine('mim:///')
         conn = result.connect()
         assert conn is Connection.get()