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


Python Cloudant.create_database方法代码示例

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


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

示例1: test_create_delete_methods

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import create_database [as 别名]
    def test_create_delete_methods(self):

        mock_resp = mock.Mock()
        mock_resp.json = mock.Mock()
        mock_resp.json.return_value = {}
        mock_resp.text = "mock response"
        mock_resp.status_code = 201

        mock_del = mock.Mock()
        mock_del.status_code = 200

        mock_get = mock.Mock()
        mock_get.status_code = 404

        self.mock_instance.put.return_value = mock_resp
        self.mock_instance.delete.return_value = mock_del
        self.mock_instance.get.return_value = mock_get

        # instantiate and connect
        c = Cloudant(self.username, self.password)
        c.connect()
        self.failUnless(self.mock_session.called)
        # create db call
        c.create_database("unittest")
        self.mock_instance.get.assert_has_calls(
            mock.call('https://steve.cloudant.com/unittest')
        )
        self.mock_instance.put.assert_has_calls(
            mock.call('https://steve.cloudant.com/unittest')
        )

        # delete db call
        mock_get.reset_mocks()
        mock_get.status_code = 200
        c.delete_database("unittest")
        self.mock_instance.get.assert_has_calls(
            mock.call('https://steve.cloudant.com/unittest')
        )

        self.mock_instance.delete.assert_has_calls(
            mock.call('https://steve.cloudant.com/unittest')
        )

        # create existing db fails
        mock_get.reset_mocks()
        mock_get.status_code = 200
        self.assertRaises(CloudantException, c.create_database, "unittest")

        # delete non-existing db fails
        mock_get.reset_mocks()
        mock_get.status_code = 404
        self.assertRaises(CloudantException, c.delete_database, "unittest")
开发者ID:evansde77,项目名称:metson,代码行数:54,代码来源:account_test.py

示例2: setup_db

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import create_database [as 别名]
def setup_db(username, password, url):
	
	dbname = "spark_data"

	client = Cloudant(username, password, url=url)

	client.connect()

	# Perform client tasks...
	session = client.session()
	print 'Username: {0}'.format(session['userCtx']['name'])
	databases = client.all_dbs()
	
	db = client.create_database(dbname)

	print 'Databases: {0}'.format(client.all_dbs())

	return db
开发者ID:benCoomes,项目名称:projectSol,代码行数:20,代码来源:sparkclient.py


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