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


Python Cloudant.connect方法代码示例

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


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

示例1: test_cors_update_origins_none

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
    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)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:37,代码来源:account_test.py

示例2: test_requests_usage

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
 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)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:11,代码来源:account_test.py

示例3: test_create_delete_methods

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [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

示例4: test_cors_configuration

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
    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)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:16,代码来源:account_test.py

示例5: test_generate_api_key

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
    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)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:16,代码来源:account_test.py

示例6: test_shared_databases

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
    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)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:16,代码来源:account_test.py

示例7: test_session_calls

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
    def test_session_calls(self):
        """test session related methods"""
        c = Cloudant(
            self.username,
            self.password,
            url='https://steve.cloudant.com',
            x_cloudant_user=self.username
            )
        c.connect()

        self.assertTrue(self.mock_session.called)

        self.assertEqual(
            self.mock_instance.auth,
            (self.username, self.password)
        )

        self.assertEqual(
            self.mock_instance.headers['X-Cloudant-User'], 
            self.username
        )

        self.assertIsNotNone(self.mock_instance.headers['User-Agent'])

        self.assertEqual('COOKIE', c.session_cookie())

        self.assertTrue(self.mock_instance.get.called)
        self.mock_instance.get.assert_has_calls(
            [ mock.call('https://steve.cloudant.com/_session') ]
        )

        self.assertTrue(self.mock_instance.post.called)
        self.mock_instance.post.assert_has_calls(
            [ mock.call(
                  'https://steve.cloudant.com/_session',
                  headers={'Content-Type': 'application/x-www-form-urlencoded'},
                  data={'password': 'abc123', 'name': 'steve'}
            ) ]
        )

        c.disconnect()
        self.assertTrue(self.mock_instance.delete.called)
        self.mock_instance.delete.assert_has_calls(
            [ mock.call('https://steve.cloudant.com/_session') ]
        )
开发者ID:rredburn,项目名称:python-cloudant,代码行数:47,代码来源:account_test.py

示例8: tela_cliente

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
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)
开发者ID:fabiolmarras,项目名称:EP,代码行数:20,代码来源:default.py

示例9: setup_db

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [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

示例10: test_cors_disable

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
    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)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:23,代码来源:account_test.py

示例11: test_cors_origins_get

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
    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)
开发者ID:rredburn,项目名称:python-cloudant,代码行数:25,代码来源:account_test.py

示例12: test_session_calls

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
    def test_session_calls(self):
        """test session related methods"""
        c = Cloudant(self.username, self.password)
        c.connect()

        self.failUnless(self.mock_session.called)

        self.assertEqual(
            self.mock_instance.auth,
            (self.username, self.password)
        )
        self.assertEqual(
            self.mock_instance.headers,
            {'X-Cloudant-User': self.username}
        )

        self.assertEqual('COOKIE', c.session_cookie())

        self.failUnless(self.mock_instance.get.called)
        self.mock_instance.get.assert_has_calls(
            mock.call('https://steve.cloudant.com/_session')
        )

        self.failUnless(self.mock_instance.post.called)
        self.mock_instance.post.assert_has_calls(
            mock.call(
                'https://steve.cloudant.com/_session',
                headers={'Content-Type': 'application/x-www-form-urlencoded'},
                data={'password': 'abc123', 'name': 'steve'}
            )
        )

        c.disconnect()
        self.failUnless(self.mock_instance.delete.called)
        self.mock_instance.delete.assert_has_calls(
            mock.call('https://steve.cloudant.com/_session')
        )
开发者ID:evansde77,项目名称:metson,代码行数:39,代码来源:account_test.py

示例13: test_usage_endpoint

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
    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
        )
开发者ID:rredburn,项目名称:python-cloudant,代码行数:26,代码来源:account_test.py

示例14: has_internet

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
        pass
    return False


if __name__ == '__main__':

    # ensure we have internet connection
    # mark every 10 minutes
    startup_time = time.time()
    while not has_internet():
        elapsed = time.time() - startup_time
        if elapsed % 600 == 0:
            print '%s mins without internet connection...' % (elapsed/60)

    # connect to cloudant client
    client.connect()

    # subscribe to client channel
    pubnub.subscribe(channels=pubnub_channel_client, callback=callback, error=callback,
                 connect=connect, reconnect=reconnect, disconnect=disconnect)

    # ensure red led is off
    GPIO.output(RED_LED, False)

    try:
        print('Booting system...')
        GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=alert)
        
        # indicate the system is ready
        GPIO.output(GREEN_LED, True)
开发者ID:ksuh90,项目名称:pi-surveillance,代码行数:32,代码来源:main.py

示例15: UnitTestDbBase

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import connect [as 别名]
class UnitTestDbBase(unittest.TestCase):
    """
    The base class for all unit tests targeting a database
    """

    @classmethod
    def setUpClass(cls):
        """
        If targeting CouchDB, Set up a CouchDB instance otherwise do nothing.
          
        Note: Admin Party is currently unsupported so we must create a 
          CouchDB user for tests to function with a CouchDB instance if one is
          not provided.
        """
        if os.environ.get('RUN_CLOUDANT_TESTS') is None:
            if os.environ.get('DB_URL') is None:
                os.environ['DB_URL'] = 'http://127.0.0.1:5984'

            if os.environ.get('DB_USER') is None:
                os.environ['DB_USER_CREATED'] = '1'
                os.environ['DB_USER'] = 'user-{0}'.format(
                    unicode_(uuid.uuid4())
                    )
                os.environ['DB_PASSWORD'] = 'password'
                resp = requests.put(
                    '{0}/_config/admins/{1}'.format(
                        os.environ['DB_URL'],
                        os.environ['DB_USER']
                        ),
                    data='"{0}"'.format(os.environ['DB_PASSWORD'])
                    )
                resp.raise_for_status()

    @classmethod
    def tearDownClass(cls):
        """
        If necessary, clean up CouchDB instance once all tests are complete.
        """
        if (os.environ.get('RUN_CLOUDANT_TESTS') is None and
            os.environ.get('DB_USER_CREATED') is not None):
            resp = requests.delete(
                '{0}://{1}:{2}@{3}/_config/admins/{4}'.format(
                    os.environ['DB_URL'].split('://', 1)[0],
                    os.environ['DB_USER'],
                    os.environ['DB_PASSWORD'],
                    os.environ['DB_URL'].split('://', 1)[1],
                    os.environ['DB_USER']
                    )
                )
            del os.environ['DB_USER_CREATED']
            del os.environ['DB_USER']
            resp.raise_for_status()

    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)

    def tearDown(self):
        """
        Ensure the client is new for each test
        """
        del self.client

    def db_set_up(self):
        """
        Set up test attributes for Database tests
        """
        self.client.connect()
        self.test_dbname = self.dbname()
        self.db = self.client._DATABASE_CLASS(self.client, self.test_dbname)
        self.db.create()

    def db_tear_down(self):
        """
        Reset test attributes for each test
        """
        self.db.delete()
        self.client.disconnect()
        del self.test_dbname
        del self.db

    def dbname(self, database_name='db'):
#.........这里部分代码省略.........
开发者ID:rredburn,项目名称:python-cloudant,代码行数:103,代码来源:unit_t_db_base.py


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