本文整理汇总了Python中mongotor.database.Database.init方法的典型用法代码示例。如果您正苦于以下问题:Python Database.init方法的具体用法?Python Database.init怎么用?Python Database.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongotor.database.Database
的用法示例。
在下文中一共展示了Database.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_not_raise_when_database_was_initiated
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_not_raise_when_database_was_initiated(self):
"""[DatabaseTestCase] - Not raises ValueError when connect to inititated database"""
database1 = Database.init("localhost:27027", dbname='test')
database2 = Database.init("localhost:27027", dbname='test')
database1.should.be.equal(database2)
示例2: test_raises_erro_when_use_collection_with_not_initialized_database
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_raises_erro_when_use_collection_with_not_initialized_database(self):
"""[CollectionTestCase] - Raises DatabaseError when use collection with a not initialized database"""
class CollectionTest(Collection):
__collection__ = 'collection_test'
Database.disconnect()
CollectionTest().save.when.called_with(callback=None) \
.throw(DatabaseError, 'you must be initialize database before perform this action')
Database.init(["localhost:27027", "localhost:27028"], dbname='test')
示例3: test_insert_and_find_with_elemmatch
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_insert_and_find_with_elemmatch(self):
documents = [{
'_id': ObjectId(),
'name': 'should be name 1',
'comment': [{'author': 'joe'}, {'author': 'ana'}]
}, {
'_id': ObjectId(),
'name': 'should be name 2',
'comment': [{'author': 'ana'}]
}]
db = Database.init(["localhost:27027", "localhost:27028"],
dbname='test')
db.articles.insert(documents, callback=self.stop)
self.wait()
db.articles.find({'comment.author': 'joe'}, ('comment.$.author', ), limit=-1, callback=self.stop)
result, _ = self.wait()
keys = result.keys()
keys.sort()
keys.should.be.equal(['_id', 'comment'])
str(result['_id']).should.be.equal(str(documents[0]['_id']))
result['comment'].should.have.length_of(1)
result['comment'][0]['author'].should.be.equal('joe')
_.should.be.none
示例4: test_raises_error_when_could_not_find_node
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_raises_error_when_could_not_find_node(self):
"""[DatabaseTestCase] - Raises DatabaseError when could not find valid nodes"""
database = Database.init(["localhost:27030"], dbname="test")
database.send_message.when.called_with("", callback=None).throw(
DatabaseError, "could not find an available node"
)
示例5: test_run_command
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_run_command(self):
"""[DatabaseTestCase] - Run a database command"""
database = Database.init(["localhost:27027"], dbname='test')
database.command('ismaster', callback=self.stop)
response, error = self.wait()
response['ok'].should.be.ok
示例6: test_send_test_message
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_send_test_message(self):
"""[DatabaseTestCase] - Send a test message to database"""
Database.init(["localhost:27027", "localhost:27028"], dbname="test")
object_id = ObjectId()
message_test = message.query(0, "mongotor_test.$cmd", 0, 1, {"driverOIDTest": object_id})
Database().send_message(message_test, callback=self.stop)
response, _ = self.wait()
response = helpers._unpack_response(response)
result = response["data"][0]
result["oid"].should.be(object_id)
result["ok"].should.be(1.0)
result["str"].should.be(str(object_id))
示例7: test_send_test_message
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_send_test_message(self):
"""[DatabaseTestCase] - Send a test message to database"""
Database.init(["localhost:27027", "localhost:27028"], dbname='test')
object_id = ObjectId()
message_test = message.query(0, 'mongotor_test.$cmd', 0, 1,
{'driverOIDTest': object_id})
Database().send_message(message_test, callback=self.stop)
response, _ = self.wait()
response = helpers._unpack_response(response)
result = response['data'][0]
result['oid'].should.be(object_id)
result['ok'].should.be(1.0)
result['str'].should.be(str(object_id))
示例8: test_raises_error_when_could_not_find_node
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_raises_error_when_could_not_find_node(self):
"""[DatabaseTestCase] - Raises DatabaseError when could not find valid nodes"""
database = Database.init(["localhost:27030"], dbname='test')
def send_message():
database.send_message('', callback=self.stop)
self.wait()
send_message.when.called.throw(DatabaseError, 'could not find an available node')
示例9: test_insert_a_single_document
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_insert_a_single_document(self):
"""[ClientTestCase] - insert a single document with client"""
db = Database.init(["localhost:27027", "localhost:27028"],
dbname='test')
document = {'_id': ObjectId(), 'name': 'shouldbename'}
db.collection_test.insert(document, callback=self.stop)
response, error = self.wait()
response['ok'].should.be.equal(1.0)
error.should.be.none
示例10: test_aggregate_collection
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_aggregate_collection(self):
"""[ClientTestCase] - aggregate command"""
db = Database.init(["localhost:27027", "localhost:27028"],
dbname='test')
documents = [{
"title": "this is my title",
"author": "bob",
"posted": datetime.now(),
"pageViews": 5,
"tags": ["good", "fun"],
}, {
"title": "this is my title",
"author": "joe",
"posted": datetime.now(),
"pageViews": 5,
"tags": ["good"],
}]
db.articles.insert(documents, callback=self.stop)
response, error = self.wait()
try:
pipeline = {
"$project": {
"author": 1,
"tags": 1,
}
}, {
"$unwind": "$tags"
}, {
"$group": {
"_id": {"tags": "$tags"},
"authors": {"$addToSet": "$author"}
}
}
db.articles.aggregate(pipeline, callback=self.stop)
response = self.wait()
response['result'][0]['_id'].should.be.equal({u'tags': u'fun'})
response['result'][0]['authors'].should.be.equal([u'bob'])
response['result'][1]['_id'].should.be.equal({u'tags': u'good'})
response['result'][1]['authors'].should.be.equal([u'joe', u'bob'])
finally:
db.articles.remove({}, callback=self.stop)
self.wait()
示例11: test_count_all_documents
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_count_all_documents(self):
"""[ClientTestCase] - counting among all documents"""
db = Database.init(["localhost:27027", "localhost:27028"],
dbname='test')
documents = [{'_id': ObjectId(), 'param': 'shouldbeparam1'},
{'_id': ObjectId(), 'param': 'shouldbeparam1'},
{'_id': ObjectId(), 'param': 'shouldbeparam2'}]
db.collection_test.insert(documents, callback=self.stop)
response, error = self.wait()
db.collection_test.count(callback=self.stop)
total = self.wait()
total.should.be.equal(3)
示例12: test_find_on_secondary
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_find_on_secondary(self):
"""[SecondaryPreferredTestCase] - test find document from secondary"""
db = Database.init(["localhost:27027", "localhost:27028"], dbname='test',
read_preference=ReadPreference.SECONDARY_PREFERRED)
db._connect(callback=self.stop)
self.wait()
doc = {'_id': ObjectId()}
db.test.insert(doc, callback=self.stop)
self.wait()
time.sleep(2)
db.test.find_one(doc, callback=self.stop)
doc_found, error = self.wait()
doc_found.should.be.eql(doc)
示例13: test_remove_document_by_spec
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_remove_document_by_spec(self):
"""[ClientTestCase] - remove a document by spec"""
db = Database.init(["localhost:27027", "localhost:27028"],
dbname='test')
documents = [{'_id': ObjectId(), 'name': 'shouldbename'},
{'_id': ObjectId(), 'name': 'shouldbename2'}]
db.collection_test.insert(documents, callback=self.stop)
response, error = self.wait()
db.collection_test.remove({'name': 'shouldbename'}, callback=self.stop)
response, error = self.wait()
response['ok'].should.be.equal(1.0)
error.should.be.none
示例14: test_raises_error_when_mode_is_secondary_and_secondary_is_down
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_raises_error_when_mode_is_secondary_and_secondary_is_down(self):
"""[ReplicaSetTestCase] - Raise error when mode is secondary and secondary is down"""
os.system("make mongo-kill-node2")
time.sleep(1) # stops are fast
try:
db = Database.init(["localhost:27027", "localhost:27028"], dbname="test")
db._connect(callback=self.stop)
self.wait()
Database().send_message.when.called_with((None, ""), read_preference=ReadPreference.SECONDARY).throw(
DatabaseError
)
finally:
os.system("make mongo-start-node2")
time.sleep(5) # wait to become secondary again
示例15: test_check_connections_when_use_cursors
# 需要导入模块: from mongotor.database import Database [as 别名]
# 或者: from mongotor.database.Database import init [as 别名]
def test_check_connections_when_use_cursors(self):
"""[ConnectionPoolTestCase] - check connections when use cursors"""
db = Database.init('localhost:27027', dbname='test', maxconnections=10, maxusage=29)
try:
for i in range(2):
db.cards.insert({'_id': ObjectId(), 'range': i}, callback=self.stop)
self.wait()
db._nodes[0].pool._connections.should.be.equal(0)
db.cards.find({}, callback=self.stop)
self.wait()
db._nodes[0].pool._connections.should.be.equal(0)
finally:
Database.disconnect()