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


Python Cloudant.update_cors_configuration方法代码示例

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


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

示例1: test_cors_update_origins_none

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

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

#.........这里部分代码省略.........
            self.client.disconnect()

    def test_generate_api_key(self):
        """
        Test the generation of an API key for this account
        """
        try:
            self.client.connect()
            expected = ['key', 'password', 'ok']
            api_key = self.client.generate_api_key()
            self.assertTrue(all(x in expected for x in api_key.keys()))
            self.assertTrue(api_key['ok'])
        finally:
            self.client.disconnect()

    def test_cors_configuration(self):
        """
        Test the retrieval of the current CORS configuration for this account
        """
        try:
            self.client.connect()
            expected = ['allow_credentials', 'enable_cors', 'origins']
            cors = self.client.cors_configuration()
            self.assertTrue(all(x in expected for x in cors.keys()))
        finally:
            self.client.disconnect()

    def test_cors_origins(self):
        """
        Test the retrieval of the CORS origins list
        """
        try:
            self.client.connect()
            origins = self.client.cors_origins()
            self.assertIsInstance(origins, list)
        finally:
            self.client.disconnect()

    def test_disable_cors(self):
        """
        Test disabling CORS (assuming CORS is enabled)
        """
        try:
            self.client.connect()
            # Save original CORS settings
            save = self.client.cors_configuration()
            # Test CORS disable
            self.assertEqual(self.client.disable_cors(), {'ok': True})
            # Restore original CORS settings
            self.client.update_cors_configuration(
                save['enable_cors'],
                save['allow_credentials'],
                save['origins'],
                True
                )
        finally:
            self.client.disconnect()

    def test_update_cors_configuration(self):
        """
        Test updating CORS configuration
        """
        try:
            self.client.connect()
            # Save original CORS settings
            save = self.client.cors_configuration()
            # Test updating CORS settings, overwriting origins
            result = self.client.update_cors_configuration(
                True,
                True,
                ['https://ibm.com'],
                True)
            self.assertEqual(result, {'ok': True})
            updated_cors = self.client.cors_configuration()
            self.assertTrue(updated_cors['enable_cors'])
            self.assertTrue(updated_cors['allow_credentials'])
            expected = ['https://ibm.com']
            self.assertTrue(all(x in expected for x in updated_cors['origins']))
            # Test updating CORS settings, adding to origins
            result = self.client.update_cors_configuration(
                True,
                True,
                ['https://ibm.cloudant.com']
                )
            self.assertEqual(result, {'ok': True})
            del updated_cors
            updated_cors = self.client.cors_configuration()
            self.assertTrue(updated_cors['enable_cors'])
            self.assertTrue(updated_cors['allow_credentials'])
            expected.append('https://ibm.cloudant.com')
            self.assertTrue(all(x in expected for x in updated_cors['origins']))
            # Restore original CORS settings
            self.client.update_cors_configuration(
                save['enable_cors'],
                save['allow_credentials'],
                save['origins'],
                True
                )
        finally:
            self.client.disconnect()
开发者ID:rredburn,项目名称:python-cloudant,代码行数:104,代码来源:account_tests.py


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