本文整理汇总了Python中pymongo.master_slave_connection.MasterSlaveConnection.drop_database方法的典型用法代码示例。如果您正苦于以下问题:Python MasterSlaveConnection.drop_database方法的具体用法?Python MasterSlaveConnection.drop_database怎么用?Python MasterSlaveConnection.drop_database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymongo.master_slave_connection.MasterSlaveConnection
的用法示例。
在下文中一共展示了MasterSlaveConnection.drop_database方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestMasterSlaveConnection
# 需要导入模块: from pymongo.master_slave_connection import MasterSlaveConnection [as 别名]
# 或者: from pymongo.master_slave_connection.MasterSlaveConnection import drop_database [as 别名]
#.........这里部分代码省略.........
return self._items.pop(0)
self.client._MasterSlaveConnection__slaves = NotRandomList()
self.assertRaises(AutoReconnect,
self.client._send_message_with_response, 'message')
self.assertEqual(4, Slave.calls)
def test_get_db(self):
def make_db(base, name):
return base[name]
self.assertRaises(InvalidName, make_db, self.client, "")
self.assertRaises(InvalidName, make_db, self.client, "te$t")
self.assertRaises(InvalidName, make_db, self.client, "te.t")
self.assertRaises(InvalidName, make_db, self.client, "te\\t")
self.assertRaises(InvalidName, make_db, self.client, "te/t")
self.assertRaises(InvalidName, make_db, self.client, "te st")
self.assertTrue(isinstance(self.client.test, Database))
self.assertEqual(self.client.test, self.client["test"])
self.assertEqual(self.client.test, Database(self.client,
"test"))
def test_database_names(self):
self.client.pymongo_test.test.save({"dummy": u"object"})
self.client.pymongo_test_mike.test.save({"dummy": u"object"})
dbs = self.client.database_names()
self.assertTrue("pymongo_test" in dbs)
self.assertTrue("pymongo_test_mike" in dbs)
def test_drop_database(self):
self.assertRaises(TypeError, self.client.drop_database, 5)
self.assertRaises(TypeError, self.client.drop_database, None)
raise SkipTest("This test often fails due to SERVER-2329")
self.client.pymongo_test.test.save({"dummy": u"object"})
dbs = self.client.database_names()
self.assertTrue("pymongo_test" in dbs)
self.client.drop_database("pymongo_test")
dbs = self.client.database_names()
self.assertTrue("pymongo_test" not in dbs)
self.client.pymongo_test.test.save({"dummy": u"object"})
dbs = self.client.database_names()
self.assertTrue("pymongo_test" in dbs)
self.client.drop_database(self.client.pymongo_test)
dbs = self.client.database_names()
self.assertTrue("pymongo_test" not in dbs)
def test_iteration(self):
def iterate():
[a for a in self.client]
self.assertRaises(TypeError, iterate)
def test_insert_find_one_in_request(self):
count = 0
for i in range(100):
self.client.start_request()
self.db.test.remove({})
self.db.test.insert({"x": i})
示例2: TestMasterSlaveConnection
# 需要导入模块: from pymongo.master_slave_connection import MasterSlaveConnection [as 别名]
# 或者: from pymongo.master_slave_connection.MasterSlaveConnection import drop_database [as 别名]
#.........这里部分代码省略.........
return self._items.pop(0)
self.connection._MasterSlaveConnection__slaves = NotRandomList()
self.assertRaises(AutoReconnect,
self.connection._send_message_with_response, 'message')
self.assertEquals(4, Slave.calls)
def test_get_db(self):
def make_db(base, name):
return base[name]
self.assertRaises(InvalidName, make_db, self.connection, "")
self.assertRaises(InvalidName, make_db, self.connection, "te$t")
self.assertRaises(InvalidName, make_db, self.connection, "te.t")
self.assertRaises(InvalidName, make_db, self.connection, "te\\t")
self.assertRaises(InvalidName, make_db, self.connection, "te/t")
self.assertRaises(InvalidName, make_db, self.connection, "te st")
self.assert_(isinstance(self.connection.test, Database))
self.assertEqual(self.connection.test, self.connection["test"])
self.assertEqual(self.connection.test, Database(self.connection,
"test"))
def test_database_names(self):
self.connection.pymongo_test.test.save({"dummy": u"object"})
self.connection.pymongo_test_mike.test.save({"dummy": u"object"})
dbs = self.connection.database_names()
self.assert_("pymongo_test" in dbs)
self.assert_("pymongo_test_mike" in dbs)
def test_drop_database(self):
self.assertRaises(TypeError, self.connection.drop_database, 5)
self.assertRaises(TypeError, self.connection.drop_database, None)
self.connection.pymongo_test.test.save({"dummy": u"object"}, safe=True)
dbs = self.connection.database_names()
self.assert_("pymongo_test" in dbs)
self.connection.drop_database("pymongo_test")
dbs = self.connection.database_names()
self.assert_("pymongo_test" not in dbs)
self.connection.pymongo_test.test.save({"dummy": u"object"})
dbs = self.connection.database_names()
self.assert_("pymongo_test" in dbs)
self.connection.drop_database(self.connection.pymongo_test)
dbs = self.connection.database_names()
self.assert_("pymongo_test" not in dbs)
def test_iteration(self):
def iterate():
[a for a in self.connection]
self.assertRaises(TypeError, iterate)
def test_insert_find_one_in_request(self):
count = 0
for i in range(100):
self.connection.start_request()
self.db.test.remove({})
self.db.test.insert({"x": i})
try:
if i != self.db.test.find_one()["x"]:
示例3: TestMasterSlaveConnection
# 需要导入模块: from pymongo.master_slave_connection import MasterSlaveConnection [as 别名]
# 或者: from pymongo.master_slave_connection.MasterSlaveConnection import drop_database [as 别名]
class TestMasterSlaveConnection(unittest.TestCase):
def setUp(self):
host = os.environ.get("DB_IP", "localhost")
self.master = Connection(host, int(os.environ.get("DB_PORT", 27017)))
self.slaves = []
try:
self.slaves.append(Connection(os.environ.get("DB_IP2", host),
int(os.environ.get("DB_PORT2",
27018)),
slave_okay=True))
except ConnectionFailure:
pass
try:
self.slaves.append(Connection(os.environ.get("DB_IP3", host),
int(os.environ.get("DB_PORT3",
27019)),
slave_okay=True))
except ConnectionFailure:
pass
if not self.slaves:
raise SkipTest()
self.connection = MasterSlaveConnection(self.master, self.slaves)
self.db = self.connection.pymongo_test
def test_types(self):
self.assertRaises(TypeError, MasterSlaveConnection, 1)
self.assertRaises(TypeError, MasterSlaveConnection, self.master, 1)
self.assertRaises(TypeError, MasterSlaveConnection, self.master, [1])
def test_repr(self):
self.assertEqual(repr(self.connection),
"MasterSlaveConnection(%r, %r)" %
(self.master, self.slaves))
def test_get_db(self):
def make_db(base, name):
return base[name]
self.assertRaises(InvalidName, make_db, self.connection, "")
self.assertRaises(InvalidName, make_db, self.connection, "te$t")
self.assertRaises(InvalidName, make_db, self.connection, "te.t")
self.assertRaises(InvalidName, make_db, self.connection, "te\\t")
self.assertRaises(InvalidName, make_db, self.connection, "te/t")
self.assertRaises(InvalidName, make_db, self.connection, "te st")
self.assert_(isinstance(self.connection.test, Database))
self.assertEqual(self.connection.test, self.connection["test"])
self.assertEqual(self.connection.test, Database(self.connection,
"test"))
def test_database_names(self):
self.connection.pymongo_test.test.save({"dummy": u"object"})
self.connection.pymongo_test_mike.test.save({"dummy": u"object"})
dbs = self.connection.database_names()
self.assert_("pymongo_test" in dbs)
self.assert_("pymongo_test_mike" in dbs)
def test_drop_database(self):
self.assertRaises(TypeError, self.connection.drop_database, 5)
self.assertRaises(TypeError, self.connection.drop_database, None)
self.connection.pymongo_test.test.save({"dummy": u"object"})
dbs = self.connection.database_names()
self.assert_("pymongo_test" in dbs)
self.connection.drop_database("pymongo_test")
dbs = self.connection.database_names()
self.assert_("pymongo_test" not in dbs)
self.connection.pymongo_test.test.save({"dummy": u"object"})
dbs = self.connection.database_names()
self.assert_("pymongo_test" in dbs)
self.connection.drop_database(self.connection.pymongo_test)
dbs = self.connection.database_names()
self.assert_("pymongo_test" not in dbs)
def test_iteration(self):
def iterate():
[a for a in self.connection]
self.assertRaises(TypeError, iterate)
def test_insert_find_one_in_request(self):
count = 0
for i in range(100):
self.connection.start_request()
self.db.test.remove({})
self.db.test.insert({"x": i})
try:
if i != self.db.test.find_one()["x"]:
count += 1
except:
count += 1
#.........这里部分代码省略.........
示例4: TestMasterSlaveConnection
# 需要导入模块: from pymongo.master_slave_connection import MasterSlaveConnection [as 别名]
# 或者: from pymongo.master_slave_connection.MasterSlaveConnection import drop_database [as 别名]
#.........这里部分代码省略.........
return self._items.pop(0)
self.connection._MasterSlaveConnection__slaves = NotRandomList()
self.assertRaises(AutoReconnect,
self.connection._send_message_with_response, 'message')
self.assertEqual(4, Slave.calls)
def test_get_db(self):
def make_db(base, name):
return base[name]
self.assertRaises(InvalidName, make_db, self.connection, "")
self.assertRaises(InvalidName, make_db, self.connection, "te$t")
self.assertRaises(InvalidName, make_db, self.connection, "te.t")
self.assertRaises(InvalidName, make_db, self.connection, "te\\t")
self.assertRaises(InvalidName, make_db, self.connection, "te/t")
self.assertRaises(InvalidName, make_db, self.connection, "te st")
self.assertTrue(isinstance(self.connection.test, Database))
self.assertEqual(self.connection.test, self.connection["test"])
self.assertEqual(self.connection.test, Database(self.connection,
"test"))
def test_database_names(self):
self.connection.pymongo_test.test.save({"dummy": u"object"})
self.connection.pymongo_test_mike.test.save({"dummy": u"object"})
dbs = self.connection.database_names()
self.assertTrue("pymongo_test" in dbs)
self.assertTrue("pymongo_test_mike" in dbs)
def test_drop_database(self):
self.assertRaises(TypeError, self.connection.drop_database, 5)
self.assertRaises(TypeError, self.connection.drop_database, None)
raise SkipTest("This test often fails due to SERVER-2329")
self.connection.pymongo_test.test.save({"dummy": u"object"}, safe=True)
dbs = self.connection.database_names()
self.assertTrue("pymongo_test" in dbs)
self.connection.drop_database("pymongo_test")
dbs = self.connection.database_names()
self.assertTrue("pymongo_test" not in dbs)
self.connection.pymongo_test.test.save({"dummy": u"object"})
dbs = self.connection.database_names()
self.assertTrue("pymongo_test" in dbs)
self.connection.drop_database(self.connection.pymongo_test)
dbs = self.connection.database_names()
self.assertTrue("pymongo_test" not in dbs)
def test_iteration(self):
def iterate():
[a for a in self.connection]
self.assertRaises(TypeError, iterate)
def test_insert_find_one_in_request(self):
count = 0
for i in range(100):
self.connection.start_request()
self.db.test.remove({})
self.db.test.insert({"x": i})