当前位置: 首页>>代码示例>>Python>>正文


Python Connection.drop_database方法代码示例

本文整理汇总了Python中mongokit.Connection.drop_database方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.drop_database方法的具体用法?Python Connection.drop_database怎么用?Python Connection.drop_database使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mongokit.Connection的用法示例。


在下文中一共展示了Connection.drop_database方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TypesTestCase

# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import drop_database [as 别名]
class TypesTestCase(unittest.TestCase):

    def setUp(self):
        self.connection = Connection()
        self.col = self.connection['test']['mongokit']
        
    def tearDown(self):
        self.connection.drop_database('test')


    def test_authorized_type(self):
       for auth_type in SchemaDocument.authorized_types:
            if auth_type is dict:
                auth_type = {}
            class MyDoc(SchemaDocument):
                structure = { "foo":auth_type }
            if type(auth_type) is dict:
                assert MyDoc() == {"foo":{}}, MyDoc()
            elif auth_type is list:
                assert MyDoc() == {"foo":[]}
            else:
                assert MyDoc() == {"foo":None}, auth_type
 
    def test_not_authorized_type(self):
        for unauth_type in [set]:
            failed = False
            try:
                class MyDoc(SchemaDocument):
                    structure = { "foo":[unauth_type] }
            except StructureError, e:
                self.assertEqual(str(e), "MyDoc: %s is not an authorized type" % unauth_type)
                failed = True
            self.assertEqual(failed, True)
            failed = False
            try:
                class MyDoc(SchemaDocument):
                    structure = { "foo":(unauth_type) }
            except StructureError, e:
                self.assertEqual(str(e), "MyDoc: %s is not an authorized type" % unauth_type)
                failed = True
            self.assertEqual(failed, True)
            failed = False
            try:
                class MyDoc2(SchemaDocument):
                    structure = { 'foo':[{int:unauth_type }]}
            except StructureError, e:
                self.assertEqual(str(e), "MyDoc2: %s is not an authorized type" % unauth_type)
                failed = True
开发者ID:ThoughtLeadr,项目名称:mongokit,代码行数:50,代码来源:test_types.py

示例2: init_db

# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import drop_database [as 别名]
def init_db(host=None, port=None, database=None):
    con = Connection(host, port)
    con.drop_database(database)
    con.register([Admin, AdminRole])
    db = Database(con, database)

    generate_index(host, port, database)

    role = db.AdminRole()
    role['name'] = u'管理员'
    role['auth_list'] = get_auth_list()
    role.save()

    user = db.Admin()
    user['email'] = u'[email protected]'
    user['name'] = u'admin'
    user['password'] = db.Admin.encode_pwd('123456')
    user['login_time'] = datetime.now()
    user['status'] = True
    user['role'] = role
    user.save()

    return 'success'
开发者ID:Lobos,项目名称:wordstore,代码行数:25,代码来源:datum.py

示例3: saveVMTypes

# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import drop_database [as 别名]
		DBSession.images.insert(tempImage)

def saveVMTypes(vmTypes):

	for vmType in vmTypes['types']:
		DBSession.vmtypes.insert(vmType)

def installPackage(package):
	easy_install.main(["-U", package])

def copyImagesToServer():

	images = DBSession.images.find()
	for image in images:
		location = image['location']
		fileName = "../src/images/" + image['name'] + "__" + str(image['_id'])
		system('scp "%s" "%s" ' % (location , fileName) )


if __name__ == "__main__":

	mongoConnection.drop_database('cloudDB')

	savePhysicalMachines(getPhysicalMachines(argv[1]))
	saveImageFiles(getImageFiles(argv[2]))
	saveVMTypes(getVMTypesDict(argv[3]))

	copyImagesToServer()


开发者ID:rishirajsinghjhelumi,项目名称:Cloud-Orchestration-Layer,代码行数:30,代码来源:setup.py

示例4: DescriptorsTestCase

# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import drop_database [as 别名]
class DescriptorsTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = Connection()
        self.col = self.connection['test']['mongokit']
        
    def tearDown(self):
        self.connection.drop_database('test')
    
    def test_list_embed_dot_notation(self):
        """Attempt to set a default for a sub element using dot notation

        Either this or test_list_embed_list_notation should pass
        """

        class ListEmbed(Document):
            use_dot_notation = True
            structure = {
                'list': [
                    {
                        'name': basestring,
                        'age': int
                    }
                ]
            }

            default_values = {
                'list.name': 'default'
            }

        self.connection.register([ListEmbed])

        doc = self.col.ListEmbed()
        self.assertDictEqual(doc, {'list': []})

        doc.list.append({'age': 23})

        self.assertDictEqual(
            doc, {
                'list': [
                    {
                        'name': 'default',
                        'age': 23
                    }
                ]
            }
        )
    
    def test_list_embed_list_notation(self):
        """Attempt to set a default for a sub element using list notation

        Either this or test_list_embed_dot_notation should pass
        """

        class ListEmbed(Document):
            use_dot_notation = True
            structure = {
                'list': [
                    {
                        'name': basestring,
                        'age': int
                    }
                ]
            }

            default_values = {
                'list': [
                    {
                        'name': 'default'
                    }
                ]
            }

        self.connection.register([ListEmbed])

        doc = self.col.ListEmbed()
        self.assertDictEqual(doc, {'list': []})

        doc.list.append({'age': 23})

        self.assertDictEqual(
            doc, {
                'list': [
                    {
                        'name': 'default',
                        'age': 23
                    }
                ]
            }
        )

    def test_list_embed_non_required_fields(self):
        """Confirm all fields are not required"""

        class ListEmbed(Document):
            use_dot_notation = True
            structure = {
                'list': [
                    {
                        'name': basestring,
                        'age': int
#.........这里部分代码省略.........
开发者ID:Pewpewarrows,项目名称:mongokit,代码行数:103,代码来源:listembed-test.py

示例5: TypesTestCase

# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import drop_database [as 别名]
class TypesTestCase(unittest.TestCase):

    def setUp(self):
        self.connection = Connection()
        self.col = self.connection['test']['mongokit']
        
    def tearDown(self):
        self.connection.drop_database('test')


    def test_authorized_type(self):
       for auth_type in SchemaDocument.authorized_types:
            if auth_type is dict:
                auth_type = {}
            class MyDoc(SchemaDocument):
                structure = { "foo":auth_type }
            if type(auth_type) is dict:
                assert MyDoc() == {"foo":{}}, MyDoc()
            elif auth_type is list:
                assert MyDoc() == {"foo":[]}
            else:
                assert MyDoc() == {"foo":None}, auth_type
 
    def test_not_authorized_type(self):
        for unauth_type in [set, str]:
            class MyDoc(SchemaDocument):
                structure = { "foo":[unauth_type] }
            self.assertRaises( StructureError, MyDoc )
            class MyDoc(SchemaDocument):
                structure = { "foo":(unauth_type) }
            self.assertRaises( StructureError, MyDoc )
            class MyDoc2(SchemaDocument):
                structure = { 'foo':[{int:unauth_type }]}
            self.assertRaises( StructureError, MyDoc2 )
            class MyDoc3(SchemaDocument):
                structure = { 'foo':[{unauth_type:int }]}
            self.assertRaises( AuthorizedTypeError, MyDoc3 )

        class MyDoc4(SchemaDocument):
            structure = {1:unicode}
        self.assertRaises( StructureError, MyDoc4 )


    def test_type_from_functions(self):
        from datetime import datetime
        class MyDoc(SchemaDocument):
            structure = {
                "foo":datetime,
            }
        assert MyDoc() == {"foo":None}, MyDoc()
        mydoc = MyDoc()
        mydoc['foo'] = datetime.now()
        mydoc.validate()

    def test_non_typed_list(self):
        class MyDoc(SchemaDocument):
            structure = {
                "foo":[]
            }
        mydoc = MyDoc()
        mydoc.validate()
        assert mydoc['foo'] == []
        mydoc['foo'] = [u"bla", 23]
        mydoc.validate()
        mydoc['foo'] = [set([1,2]), "bla"]
        self.assertRaises(AuthorizedTypeError, mydoc.validate)
        mydoc['foo'] = u"bla"
        self.assertRaises(SchemaTypeError, mydoc.validate)

#        class MyDoc(SchemaDocument):
#            structure = {
#                "foo":list
#            }
#        mydoc = MyDoc()
#        mydoc.validate()
#        assert mydoc['foo'] == []
#        mydoc['foo'] = [u"bla", 23]
#        mydoc.validate()
#        mydoc['foo'] = [set([1,2]), "bla"]
#        self.assertRaises(AuthorizedTypeError, mydoc.validate)
  
    def test_typed_list(self):
        class MyDoc(SchemaDocument):
            structure = {
                "foo":[int]
            }
        mydoc = MyDoc()
        mydoc.validate()
        assert mydoc['foo'] == []
        mydoc['foo'] = [1,2,3]
        mydoc.validate()
        mydoc['foo'] = [u"bla"]
        self.assertRaises(SchemaTypeError, mydoc.validate)

    def test_typed_list_with_dict(self):
        class MyDoc(SchemaDocument):
            structure = {
                "foo":[{unicode:int}]
            }
        mydoc = MyDoc()
#.........这里部分代码省略.........
开发者ID:boban-dj,项目名称:mongokit,代码行数:103,代码来源:test_types.py

示例6: DescriptorsTestCase

# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import drop_database [as 别名]
class DescriptorsTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = Connection()
        self.col = self.connection["test"]["mongokit"]

    def tearDown(self):
        self.connection.drop_database("test")

    def test_list_embed_dot_notation(self):
        """Attempt to set a default for a sub element using dot notation

        Either this or test_list_embed_list_notation should pass
        """

        class ListEmbed(Document):
            use_dot_notation = True
            structure = {"list": [{"name": basestring, "age": int}]}

            default_values = {"list.name": "default"}

        self.connection.register([ListEmbed])

        doc = self.col.ListEmbed()
        self.assertDictEqual(doc, {"list": []})

        doc.list.append({"age": 23})

        self.assertDictEqual(doc, {"list": [{"name": "default", "age": 23}]})

    def test_list_embed_list_notation(self):
        """Attempt to set a default for a sub element using list notation

        Either this or test_list_embed_dot_notation should pass
        """

        class ListEmbed(Document):
            use_dot_notation = True
            structure = {"list": [{"name": basestring, "age": int}]}

            default_values = {"list": [{"name": "default"}]}

        self.connection.register([ListEmbed])

        doc = self.col.ListEmbed()
        self.assertDictEqual(doc, {"list": [{"name": "default"}]})

        doc.list[0]["age"] = 23

        self.assertDictEqual(doc, {"list": [{"name": "default", "age": 23}]})

    def test_list_embed_non_required_fields(self):
        """Confirm all fields are not required"""

        class ListEmbed(Document):
            use_dot_notation = True
            structure = {"list": [{"name": basestring, "age": int}]}

        self.connection.register([ListEmbed])

        doc = self.col.ListEmbed()
        self.assertDictEqual(doc, {"list": []})

        doc.list.append({"age": 23})

        self.assertDictEqual(doc, {"list": [{"age": 23}]})

        # Should validate fine
        doc.validate()

    def test_list_embed_required_fields_dot_notation(self):
        """Confirm list of object required field validation works"""

        class ListEmbed(Document):
            use_dot_notation = True
            structure = {"list": [{"name": basestring, "age": int}]}

            required_fields = ["list.name"]

        self.connection.register([ListEmbed])

        doc = self.col.ListEmbed()
        self.assertDictEqual(doc, {"list": []})

        doc.list = [{"name": "bob"}]

        self.assertDictEqual(doc, {"list": [{"name": "bob"}]})

        # Should validate fine
        doc.validate()

        doc.list = [{"age": 23}]

        self.assertDictEqual(doc, {"list": [{"age": 23}]})

        try:
            doc.validate()
            self.fail("Not a valid document")
        except:
            pass
开发者ID:petersng,项目名称:mongokit,代码行数:101,代码来源:test_embed_list.py

示例7: InheritedQueriesTestCase

# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import drop_database [as 别名]
class InheritedQueriesTestCase(unittest.TestCase):
    def setUp(self):
        self.connection = Connection(safe=True)
        self.col = self.connection['test']['mongolite']
        
    def tearDown(self):
        self.connection.drop_database('test')

    def test_use_inherited_queries(self):
        @self.connection.register
        class A(Document):
            __database__ = 'test'
            __collection__ = 'mongolite'
            structure = {
                '_type': unicode,
                'a':{
                    'foo': int,
                    'bar': unicode,
                }
            }

        @self.connection.register
        class B(A):
            structure = {
                'b': {
                    'eggs': float,
                }
            }

        doc_a = self.connection.A()
        self.assertEqual(doc_a['_type'], 'A')
        doc_a['a']['foo'] = 3
        doc_a['a']['bar'] = u'Hello World'
        doc_a.save()

        doc_b = self.connection.B()
        self.assertEqual(doc_b['_type'], 'B')
        doc_b['a']['foo'] = 42
        doc_b['a']['bar'] = u'bye bye'
        doc_b['b']['eggs'] = 3.14
        doc_b.save()

        self.assertTrue(isinstance(self.connection.A.find_one({'_id':doc_b['_id']}), B))
        self.assertTrue(isinstance(self.connection.A.find({'_id':doc_b['_id']}).next(), B))

    def test_inherited_queries_without___collection__(self):
        @self.connection.register
        class A(Document):
            structure = {
                '_type': unicode,
                'a':{
                    'foo': int,
                    'bar': unicode,
                }
            }

        @self.connection.register
        class B(A):
            structure = {
                'b': {
                    'eggs': float,
                }
            }

        doc_a = self.col.A()
        self.assertEqual(doc_a['_type'], 'A')
        doc_a['a']['foo'] = 3
        doc_a['a']['bar'] = u'Hello World'
        doc_a.save()

        doc_b = self.col.B()
        self.assertEqual(doc_b['_type'], 'B')
        doc_b['a']['foo'] = 42
        doc_b['a']['bar'] = u'bye bye'
        doc_b['b']['eggs'] = 3.14
        doc_b.save()

        self.assertTrue(isinstance(self.col.A.find_one({'_id':doc_b['_id']}), B))
        self.assertTrue(isinstance(self.col.A.find({'_id':doc_b['_id']}).next(), B))

    def test_type_field_is_None(self):
        @self.connection.register
        class A(Document):
            type_field = None
            structure = {
                '_type': unicode,
                'a':{
                    'foo': int,
                    'bar': unicode,
                }
            }

        @self.connection.register
        class B(A):
            structure = {
                'b': {
                    'eggs': float,
                }
            }

#.........这里部分代码省略.........
开发者ID:Ink,项目名称:mongokit,代码行数:103,代码来源:test_inherited_queries.py

示例8: TypesTestCase

# 需要导入模块: from mongokit import Connection [as 别名]
# 或者: from mongokit.Connection import drop_database [as 别名]
class TypesTestCase(unittest.TestCase):

    def setUp(self):
        self.connection = Connection()
        self.col = self.connection['test']['mongokit']

    def tearDown(self):
        self.connection.drop_database('test')


    def test_authorized_type(self):
       for auth_type in SchemaDocument.authorized_types:
            if auth_type is dict:
                auth_type = {}
            class MyDoc(SchemaDocument):
                structure = { "foo":auth_type }
            if type(auth_type) is dict:
                assert MyDoc() == {"foo":{}}, MyDoc()
            elif auth_type is list:
                assert MyDoc() == {"foo":[]}
            else:
                assert MyDoc() == {"foo":None}, auth_type

    def test_not_authorized_type(self):
        for unauth_type in [set]:
            failed = False
            try:
                class MyDoc(SchemaDocument):
                    structure = { "foo":[unauth_type] }
            except StructureError as e:
                self.assertEqual(str(e), "MyDoc: %s is not an authorized type" % unauth_type)
                failed = True
            self.assertEqual(failed, True)
            failed = False
            try:
                class MyDoc(SchemaDocument):
                    structure = { "foo":(unauth_type) }
            except StructureError as e:
                self.assertEqual(str(e), "MyDoc: %s is not an authorized type" % unauth_type)
                failed = True
            self.assertEqual(failed, True)
            failed = False
            try:
                class MyDoc2(SchemaDocument):
                    structure = { 'foo':[{int:unauth_type }]}
            except StructureError as e:
                self.assertEqual(str(e), "MyDoc2: %s is not an authorized type" % unauth_type)
                failed = True
            self.assertEqual(failed, True)
            failed = False
            try:
                class MyDoc3(SchemaDocument):
                    structure = { 'foo':[{unauth_type:int }]}
            except AuthorizedTypeError as e:
                self.assertEqual(str(e), "MyDoc3: %s is not an authorized type" % unauth_type)
                failed = True
            self.assertEqual(failed, True)

        failed = False
        try:
            class MyDoc4(SchemaDocument):
                structure = {1:str}
        except StructureError as e:
            self.assertEqual(str(e), "MyDoc4: 1 must be a string or a type")
            failed = True
        self.assertEqual(failed, True)


    def test_type_from_functions(self):
        from datetime import datetime
        class MyDoc(SchemaDocument):
            structure = {
                "foo":datetime,
            }
        assert MyDoc() == {"foo":None}, MyDoc()
        mydoc = MyDoc()
        mydoc['foo'] = datetime.now()
        mydoc.validate()

    def test_non_typed_list(self):
        class MyDoc(SchemaDocument):
            structure = {
                "foo":[]
            }
        mydoc = MyDoc()
        mydoc.validate()
        assert mydoc['foo'] == []
        mydoc['foo'] = ["bla", 23]
        mydoc.validate()
        mydoc['foo'] = [set([1,2]), "bla"]
        self.assertRaises(AuthorizedTypeError, mydoc.validate)
        mydoc['foo'] = "bla"
        self.assertRaises(SchemaTypeError, mydoc.validate)

#        class MyDoc(SchemaDocument):
#            structure = {
#                "foo":list
#            }
#        mydoc = MyDoc()
#        mydoc.validate()
#.........这里部分代码省略.........
开发者ID:CodeSolid,项目名称:mongokit-py3,代码行数:103,代码来源:test_types.py


注:本文中的mongokit.Connection.drop_database方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。