本文整理汇总了Python中cloudant.account.Cloudant类的典型用法代码示例。如果您正苦于以下问题:Python Cloudant类的具体用法?Python Cloudant怎么用?Python Cloudant使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cloudant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cors_update_origins_none
def test_cors_update_origins_none(self):
"""test updating the cors config"""
resp = {
"enable_cors": True,
"allow_credentials": True,
"origins": []
}
mock_get = mock.Mock()
mock_get.raise_for_status = mock.Mock()
mock_get.json = mock.Mock()
mock_get.json.return_value = {
"enable_cors": True,
"allow_credentials": True,
"origins": ["https://example.com"]
}
self.mock_instance.get = mock.Mock()
self.mock_instance.get.return_value = mock_get
mock_put = mock.Mock()
mock_put.raise_for_status = mock.Mock()
mock_put.json = mock.Mock()
mock_put.json.return_value = resp
self.mock_instance.put.return_value = mock_put
c = Cloudant(self.username, self.password, account=self.username)
c.connect()
cors = c.update_cors_configuration(
enable_cors=True,
allow_credentials=True
)
self.assertEqual(cors, resp)
self.assertTrue(self.mock_instance.get.called)
self.assertTrue(self.mock_instance.put.called)
示例2: test_requests_usage
def test_requests_usage(self):
with mock.patch(
'cloudant.account.Cloudant._usage_endpoint'
) as mock_usage:
mock_usage.return_value = {'usage': 'mock'}
c = Cloudant(self.username, self.password, account=self.username)
c.connect()
bill = c.requests_usage(2015, 12)
self.assertEqual(bill, mock_usage.return_value)
示例3: test_cors_configuration
def test_cors_configuration(self):
"""test getting cors config"""
mock_resp = mock.Mock()
mock_resp.raise_for_status = mock.Mock()
mock_resp.json = mock.Mock()
mock_resp.json.return_value = {'cors': 'blimey'}
self.mock_instance.get = mock.Mock()
self.mock_instance.get.return_value = mock_resp
c = Cloudant(self.username, self.password, account=self.username)
c.connect()
cors = c.cors_configuration()
self.assertEqual(cors, mock_resp.json.return_value)
self.assertTrue(mock_resp.raise_for_status.called)
示例4: test_generate_api_key
def test_generate_api_key(self):
mock_resp = mock.Mock()
mock_resp.raise_for_status = mock.Mock()
mock_resp.json = mock.Mock()
mock_resp.json.return_value = {'api': 'token'}
self.mock_instance.post = mock.Mock()
self.mock_instance.post.return_value = mock_resp
c = Cloudant(self.username, self.password, account=self.username)
c.connect()
api_key = c.generate_api_key()
self.assertEqual(api_key, {'api': 'token'})
self.assertTrue(mock_resp.raise_for_status.called)
示例5: test_shared_databases
def test_shared_databases(self):
mock_resp = mock.Mock()
mock_resp.raise_for_status = mock.Mock()
mock_resp.json = mock.Mock()
mock_resp.json.return_value = {'shared_databases': ['database1', 'database2']}
self.mock_instance.get = mock.Mock()
self.mock_instance.get.return_value = mock_resp
c = Cloudant(self.username, self.password, account=self.username)
c.connect()
shared = c.shared_databases()
self.assertEqual(shared, ['database1', 'database2'])
self.assertTrue(mock_resp.raise_for_status.called)
示例6: connect_to_db
def connect_to_db(self):
self.file_upload_path = os.path.dirname(__file__) + "\\templates\\file_downloads"
self.URL_TO_DOWNLOAD = "https://f0ebf985-0718-42ab-81c8-d9a4749781fe-bluemix.cloudant.com"
self.client = Cloudant()
self.client.connect();
self.session = self.client.session();
self.database = self.client['files_data'];
示例7: tela_cliente
def tela_cliente():
txid = request.vars.getlist("txid")
if not txid:
return "Eh preciso informar uma transacao para usar essa funcao"
from cloudant.account import Cloudant
cloudantDB = "easypay"
client = Cloudant("rcsousa", "[email protected]@m0r", account="rcsousa")
client.connect()
db = client[cloudantDB]
doc = db[txid[0]]
id = doc['_id']
item = doc['item']
quantidade = doc['quantidade']
valor = doc['valor']
timestamp = doc['timestamp']
figura = doc['figura']
result = {"id": id, "item" : item, "quantidade" : quantidade, "valor" : valor, "timestamp" : timestamp, "figura" : figura}
return dict(ordem=result, user=auth.user)
示例8: test_constructor_with_account
def test_constructor_with_account(self):
"""
Test instantiating an account object using an account name
"""
# Ensure that the client is new
del self.client
self.client = Cloudant(self.user, self.pwd, account=self.account)
self.assertEqual(
self.client.cloudant_url,
'https://{0}.cloudant.com'.format(self.account)
)
示例9: setUp
def setUp(self):
"""
Set up test attributes for unit tests targeting a database
"""
if os.environ.get('RUN_CLOUDANT_TESTS') is None:
self.user = os.environ['DB_USER']
self.pwd = os.environ['DB_PASSWORD']
self.url = os.environ['DB_URL']
self.client = CouchDB(self.user, self.pwd, url=self.url)
else:
self.account = os.environ.get('CLOUDANT_ACCOUNT')
self.user = os.environ.get('DB_USER')
self.pwd = os.environ.get('DB_PASSWORD')
self.url = os.environ.get(
'DB_URL',
'https://{0}.cloudant.com'.format(self.account))
self.client = Cloudant(
self.user,
self.pwd,
url=self.url,
x_cloudant_user=self.account)
示例10: test_cors_disable
def test_cors_disable(self):
"""test disabling cors"""
resp = {
"enable_cors": False,
"allow_credentials": False,
"origins": []
}
mock_put = mock.Mock()
mock_put.raise_for_status = mock.Mock()
mock_put.json = mock.Mock()
mock_put.json.return_value = resp
self.mock_instance.put.return_value = mock_put
c = Cloudant(self.username, self.password, account=self.username)
c.connect()
cors = c.disable_cors()
self.assertEqual(cors, resp)
self.assertTrue(self.mock_instance.get.called)
self.assertTrue(self.mock_instance.put.called)
示例11: test_cors_origins_get
def test_cors_origins_get(self):
"""test getting cors origins"""
resp = {
"enable_cors": True,
"allow_credentials": True,
"origins": [
"https://example.com",
"https://www.example.com"
]
}
mock_resp = mock.Mock()
mock_resp.raise_for_status = mock.Mock()
mock_resp.json = mock.Mock()
mock_resp.json.return_value = resp
self.mock_instance.get.return_value = mock_resp
c = Cloudant(self.username, self.password, account=self.username)
c.connect()
origins = c.cors_origins()
self.assertEqual(origins, resp['origins'])
self.assertTrue(self.mock_instance.get.called)
示例12: test_create_delete_methods
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")
示例13: test_usage_endpoint
def test_usage_endpoint(self):
"""test the usage endpoint method"""
mock_resp = mock.Mock()
mock_resp.raise_for_status = mock.Mock()
mock_resp.json = mock.Mock()
mock_resp.json.return_value = {'usage': 'mock'}
mock_get = mock.Mock()
mock_get.return_value = mock_resp
self.mock_instance.get = mock_get
c = Cloudant(self.username, self.password, account=self.username)
c.connect()
usage = c._usage_endpoint('endpoint', 2015, 12)
self.assertEqual(usage, mock_resp.json.return_value)
self.assertTrue(mock_resp.raise_for_status.called)
mock_get.assert_has_calls( [ mock.call('endpoint/2015/12') ] )
self.assertRaises(
CloudantException,
c._usage_endpoint, 'endpoint', month=12
)
示例14: setUp
def setUp(self):
"""
Set up test attributes for Cloudant Account tests
"""
self.account = os.environ.get('CLOUDANT_ACCOUNT')
self.user = os.environ.get('CLOUDANT_USER')
self.pwd = os.environ.get('CLOUDANT_PASSWORD')
self.url = os.environ.get(
'CLOUDANT_URL',
'https://{0}.cloudant.com'.format(self.account)
)
self.client = Cloudant(
self.user,
self.pwd,
url=self.url,
x_cloudant_user=self.account
)
示例15: setup_db
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