本文整理汇总了Python中mongokit.Connection.database_names方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.database_names方法的具体用法?Python Connection.database_names怎么用?Python Connection.database_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongokit.Connection
的用法示例。
在下文中一共展示了Connection.database_names方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_test_database_by_specific_good_name
# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import database_names [as 别名]
def test_create_test_database_by_specific_good_name(self):
from django.conf import settings
try:
assert 'mongodb' in settings.DATABASES
except AttributeError:
# Django <1.2
return
settings.DATABASES['mongodb']['TEST_NAME'] = "test_mustard"
old_database_name = settings.DATABASES['mongodb']['NAME']
from django.db import connections
connection = connections['mongodb']
connection.creation.create_test_db()
test_database_name = settings.DATABASES['mongodb']['NAME']
self.assertTrue('test_' in test_database_name)
from mongokit import Connection
con = Connection()
# the test database isn't created till it's needed
self.assertTrue(test_database_name not in con.database_names())
# creates it
db = con[settings.DATABASES['mongodb']['NAME']]
coll = db.test_collection_name
# do a query on the collection to force the database to be created
list(coll.find())
test_database_name = settings.DATABASES['mongodb']['NAME']
self.assertTrue(test_database_name in con.database_names())
connection.creation.destroy_test_db(old_database_name)
self.assertTrue('test_mustard' not in settings.DATABASES['mongodb']['NAME'])
self.assertTrue(test_database_name not in con.database_names())
示例2: test_create_test_database
# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import database_names [as 别名]
def test_create_test_database(self):
from django.conf import settings
try:
from django_mongokit.shortcut import DATABASE_CONF
assert DATABASE_CONF in settings.DATABASES
except AttributeError:
# Django <1.2
return # :(
old_database_name = settings.DATABASES[DATABASE_CONF]['NAME']
assert 'test_' not in old_database_name
# pretend we're the Django 'test' command
from django.db import connections
connection = connections[DATABASE_CONF]
connection.creation.create_test_db()
test_database_name = settings.DATABASES[DATABASE_CONF]['NAME']
self.assertTrue('test_' in test_database_name)
from mongokit import Connection
host = settings.DATABASES[DATABASE_CONF]['HOST']
port = int(settings.DATABASES[DATABASE_CONF]['PORT'] or 27017)
con = Connection(host=host, port=port)
# the test database isn't created till it's needed
self.assertTrue(test_database_name not in con.database_names())
# creates it
db = con[settings.DATABASES[DATABASE_CONF]['NAME']]
coll = db.test_collection_name
# do a query on the collection to force the database to be created
list(coll.find())
test_database_name = settings.DATABASES[DATABASE_CONF]['NAME']
self.assertTrue(test_database_name in con.database_names())
connection.creation.destroy_test_db(old_database_name)
self.assertTrue('test_' not in settings.DATABASES[DATABASE_CONF]['NAME'])
self.assertTrue(test_database_name not in con.database_names())
# this should work even though it doesn't need to do anything
connection.close()