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


Python Cloudant.disconnect方法代码示例

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


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

示例1: test_session_calls

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

示例2: test_session_calls

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

示例3: UnitTestDbBase

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

示例4: CloudantAccountTests

# 需要导入模块: from cloudant.account import Cloudant [as 别名]
# 或者: from cloudant.account.Cloudant import disconnect [as 别名]
class CloudantAccountTests(UnitTestDbBase):
    """
    Cloudant specific Account unit tests
    """
    
    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)
            )

    def test_connect_headers(self):
        """
        Test that the appropriate request headers are set
        """
        try:
            self.client.connect()
            self.assertEqual(
                self.client.r_session.headers['X-Cloudant-User'],
                self.account
                )
            agent = self.client.r_session.headers.get('User-Agent')
            self.assertTrue(agent.startswith('python-cloudant'))
        finally:
            self.client.disconnect()

    def test_billing_data(self):
        """
        Test the retrieval of billing data
        """
        try:
            self.client.connect()
            expected = [
                'data_volume',
                'total',
                'start',
                'end',
                'http_heavy',
                'http_light'
                ]
            # Test using year and month
            year = datetime.now().year
            month = datetime.now().month
            data = self.client.bill(year, month)
            self.assertTrue(all(x in expected for x in data.keys()))
            #Test without year and month arguments
            del data
            data = self.client.bill()
            self.assertTrue(all(x in expected for x in data.keys()))
        finally:
            self.client.disconnect()

    def test_volume_usage_data(self):
        """
        Test the retrieval of volume usage data
        """
        try:
            self.client.connect()
            expected = [
                'data_vol',
                'granularity',
                'start',
                'end'
                ]
            # Test using year and month
            year = datetime.now().year
            month = datetime.now().month
            data = self.client.volume_usage(year, month)
            self.assertTrue(all(x in expected for x in data.keys()))
            #Test without year and month arguments
            del data
            data = self.client.volume_usage()
            self.assertTrue(all(x in expected for x in data.keys()))
        finally:
            self.client.disconnect()

    def test_requests_usage_data(self):
        """
        Test the retrieval of requests usage data
        """
        try:
            self.client.connect()
            expected = [
                'requests',
                'granularity',
                'start',
                'end'
                ]
            # Test using year and month
            year = datetime.now().year
            month = datetime.now().month
            data = self.client.requests_usage(year, month)
            self.assertTrue(all(x in expected for x in data.keys()))
            #Test without year and month arguments
#.........这里部分代码省略.........
开发者ID:rredburn,项目名称:python-cloudant,代码行数:103,代码来源:account_tests.py


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