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


Python mock.Mock方法代码示例

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


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

示例1: test_get_taa_required

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_get_taa_required(self):
        request = async_mock.MagicMock()
        request.app = self.app
        accepted = {
            "mechanism": "dummy",
            "time": 1234567890,
        }
        taa_info = {"taa_required": True}

        with async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as json_response:
            self.ledger.LEDGER_TYPE = "indy"
            self.ledger.get_txn_author_agreement.return_value = taa_info
            self.ledger.get_latest_txn_author_acceptance.return_value = accepted
            result = await test_module.ledger_get_taa(request)
            taa_info["taa_accepted"] = accepted
            json_response.assert_called_once_with({"result": taa_info})
            assert result is json_response.return_value 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:21,代码来源:test_routes.py

示例2: test_create_registry_no_such_cred_def

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_create_registry_no_such_cred_def(self):
        CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default"
        request = async_mock.MagicMock()
        request.app = self.app
        request.json = async_mock.CoroutineMock(
            return_value={
                "max_cred_num": "1000",
                "credential_definition_id": CRED_DEF_ID,
            }
        )

        with async_mock.patch.object(
            self.storage, "search_records", autospec=True
        ) as mock_search, async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as mock_json_response:
            mock_search.return_value.fetch_all = async_mock.CoroutineMock(
                return_value=False
            )

            with self.assertRaises(HTTPNotFound):
                result = await test_module.revocation_create_registry(request)
            mock_json_response.assert_not_called() 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:25,代码来源:test_routes.py

示例3: test_get_registry

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_get_registry(self):
        REV_REG_ID = "{}:4:{}:3:CL:1234:default:CL_ACCUM:default".format(
            self.test_did, self.test_did
        )
        request = async_mock.MagicMock()
        request.app = self.app
        request.match_info = {"rev_reg_id": REV_REG_ID}

        with async_mock.patch.object(
            test_module, "IndyRevocation", autospec=True
        ) as mock_indy_revoc, async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as mock_json_response:
            mock_indy_revoc.return_value = async_mock.MagicMock(
                get_issuer_rev_reg_record=async_mock.CoroutineMock(
                    return_value=async_mock.MagicMock(
                        serialize=async_mock.MagicMock(return_value="dummy")
                    )
                )
            )

            result = await test_module.get_registry(request)
            mock_json_response.assert_called_once_with({"result": "dummy"})
            assert result is mock_json_response.return_value 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:26,代码来源:test_routes.py

示例4: test_get_registry_not_found

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_get_registry_not_found(self):
        REV_REG_ID = "{}:4:{}:3:CL:1234:default:CL_ACCUM:default".format(
            self.test_did, self.test_did
        )
        request = async_mock.MagicMock()
        request.app = self.app
        request.match_info = {"rev_reg_id": REV_REG_ID}

        with async_mock.patch.object(
            test_module, "IndyRevocation", autospec=True
        ) as mock_indy_revoc, async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as mock_json_response:
            mock_indy_revoc.return_value = async_mock.MagicMock(
                get_issuer_rev_reg_record=async_mock.CoroutineMock(
                    side_effect=test_module.StorageNotFoundError(error_code="dummy")
                )
            )

            with self.assertRaises(HTTPNotFound):
                result = await test_module.get_registry(request)
            mock_json_response.assert_not_called() 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:test_routes.py

示例5: test_get_active_registry

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_get_active_registry(self):
        CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default"
        request = async_mock.MagicMock()
        request.app = self.app
        request.match_info = {"cred_def_id": CRED_DEF_ID}

        with async_mock.patch.object(
            test_module, "IndyRevocation", autospec=True
        ) as mock_indy_revoc, async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as mock_json_response:
            mock_indy_revoc.return_value = async_mock.MagicMock(
                get_active_issuer_rev_reg_record=async_mock.CoroutineMock(
                    return_value=async_mock.MagicMock(
                        serialize=async_mock.MagicMock(return_value="dummy")
                    )
                )
            )

            result = await test_module.get_active_registry(request)
            mock_json_response.assert_called_once_with({"result": "dummy"})
            assert result is mock_json_response.return_value 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:test_routes.py

示例6: test_get_active_registry_not_found

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_get_active_registry_not_found(self):
        CRED_DEF_ID = f"{self.test_did}:3:CL:1234:default"
        request = async_mock.MagicMock()
        request.app = self.app
        request.match_info = {"cred_def_id": CRED_DEF_ID}

        with async_mock.patch.object(
            test_module, "IndyRevocation", autospec=True
        ) as mock_indy_revoc, async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as mock_json_response:
            mock_indy_revoc.return_value = async_mock.MagicMock(
                get_active_issuer_rev_reg_record=async_mock.CoroutineMock(
                    side_effect=test_module.StorageNotFoundError(error_code="dummy")
                )
            )

            with self.assertRaises(HTTPNotFound):
                result = await test_module.get_active_registry(request)
            mock_json_response.assert_not_called() 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:22,代码来源:test_routes.py

示例7: test_get_tails_file

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_get_tails_file(self):
        REV_REG_ID = "{}:4:{}:3:CL:1234:default:CL_ACCUM:default".format(
            self.test_did, self.test_did
        )
        request = async_mock.MagicMock()
        request.app = self.app
        request.match_info = {"rev_reg_id": REV_REG_ID}

        with async_mock.patch.object(
            test_module, "IndyRevocation", autospec=True
        ) as mock_indy_revoc, async_mock.patch.object(
            test_module.web, "FileResponse", async_mock.Mock()
        ) as mock_file_response:
            mock_indy_revoc.return_value = async_mock.MagicMock(
                get_issuer_rev_reg_record=async_mock.CoroutineMock(
                    return_value=async_mock.MagicMock(tails_local_path="dummy")
                )
            )

            result = await test_module.get_tails_file(request)
            mock_file_response.assert_called_once_with(path="dummy", status=200)
            assert result is mock_file_response.return_value 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:test_routes.py

示例8: test_publish_registry_not_found

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_publish_registry_not_found(self):
        REV_REG_ID = "{}:4:{}:3:CL:1234:default:CL_ACCUM:default".format(
            self.test_did, self.test_did
        )
        request = async_mock.MagicMock()
        request.app = self.app
        request.match_info = {"rev_reg_id": REV_REG_ID}

        with async_mock.patch.object(
            test_module, "IndyRevocation", autospec=True
        ) as mock_indy_revoc, async_mock.patch.object(
            test_module.web, "FileResponse", async_mock.Mock()
        ) as mock_json_response:
            mock_indy_revoc.return_value = async_mock.MagicMock(
                get_issuer_rev_reg_record=async_mock.CoroutineMock(
                    side_effect=test_module.StorageNotFoundError(error_code="dummy")
                )
            )

            with self.assertRaises(HTTPNotFound):
                result = await test_module.publish_registry(request)
            mock_json_response.assert_not_called() 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:test_routes.py

示例9: test_credentials_get

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_credentials_get(self):
        request = async_mock.MagicMock(
            app=self.app, match_info={"credential_id": "dummy"}
        )

        request.app["request_context"].inject = async_mock.CoroutineMock(
            return_value=async_mock.MagicMock(
                get_credential=async_mock.CoroutineMock(
                    return_value=json.dumps({"hello": "world"})
                )
            )
        )

        with async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as json_response:
            result = await test_module.credentials_get(request)
            json_response.assert_called_once_with({"hello": "world"})
            assert result is json_response.return_value 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:21,代码来源:test_routes.py

示例10: test_credentials_list

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_credentials_list(self):
        request = async_mock.MagicMock(
            app=self.app, query={"start": "0", "count": "10"}
        )

        request.app["request_context"].inject = async_mock.CoroutineMock(
            return_value=async_mock.MagicMock(
                get_credentials=async_mock.CoroutineMock(
                    return_value={"hello": "world"}
                )
            )
        )

        with async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as json_response:
            result = await test_module.credentials_list(request)
            json_response.assert_called_once_with({"results": {"hello": "world"}})
            assert result is json_response.return_value 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:21,代码来源:test_routes.py

示例11: test_load_postgres_plugin_config_x_raise

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_load_postgres_plugin_config_x_raise(self):
        storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}'
        storage_creds = '{"account":"test"}'
        mock_stg_lib = async_mock.MagicMock(
            postgresstorage_init=async_mock.MagicMock(return_value=0),
            init_storagetype=async_mock.MagicMock(return_value=2),
        )
        with async_mock.patch.object(
            test_module.cdll, "LoadLibrary", async_mock.Mock()
        ) as mock_load:
            mock_load.return_value = mock_stg_lib
            with self.assertRaises(OSError) as context:
                test_module.load_postgres_plugin(
                    storage_config, storage_creds, raise_exc=True
                )
            assert "unable to configure postgres" in str(context.exception) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:18,代码来源:test_plugin.py

示例12: test_load_postgres_plugin_bad_json_x_raise

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_load_postgres_plugin_bad_json_x_raise(self):
        storage_config = '{"wallet_scheme":"MultiWalletSingleTable"}'
        storage_creds = '"account":"test"'
        mock_stg_lib = async_mock.MagicMock(
            postgresstorage_init=async_mock.MagicMock(return_value=0),
            init_storagetype=async_mock.MagicMock(return_value=2),
        )
        with async_mock.patch.object(
            test_module.cdll, "LoadLibrary", async_mock.Mock()
        ) as mock_load:
            mock_load.return_value = mock_stg_lib
            with self.assertRaises(OSError) as context:
                test_module.load_postgres_plugin(
                    storage_config, storage_creds, raise_exc=True
                )
            assert "Invalid stringified JSON input" in str(context.exception) 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:18,代码来源:test_plugin.py

示例13: test_create_did

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_create_did(self):
        request = async_mock.MagicMock()
        request.app = self.app
        with async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as json_response, async_mock.patch.object(
            test_module, "format_did_info", async_mock.Mock()
        ) as format_did_info:
            self.wallet.create_local_did.return_value = DIDInfo(
                self.test_did, self.test_verkey, {}
            )
            result = await test_module.wallet_create_did(request)
            format_did_info.assert_called_once_with(
                self.wallet.create_local_did.return_value
            )
            json_response.assert_called_once_with(
                {"result": format_did_info.return_value}
            )
            assert result is json_response.return_value 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:21,代码来源:test_routes.py

示例14: test_did_list

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_did_list(self):
        request = async_mock.MagicMock()
        request.app = self.app
        request.query = {}
        with async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as json_response, async_mock.patch.object(
            test_module, "format_did_info", async_mock.Mock()
        ) as format_did_info:
            self.wallet.get_local_dids.return_value = [
                DIDInfo(self.test_did, self.test_verkey, {})
            ]
            format_did_info.return_value = {"did": self.test_did}
            result = await test_module.wallet_did_list(request)
            format_did_info.assert_called_once_with(
                self.wallet.get_local_dids.return_value[0]
            )
            json_response.assert_called_once_with(
                {"results": [format_did_info.return_value]}
            )
            assert json_response.return_value is json_response()
            assert result is json_response.return_value 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:test_routes.py

示例15: test_did_list_filter_public

# 需要导入模块: from asynctest import mock [as 别名]
# 或者: from asynctest.mock import Mock [as 别名]
def test_did_list_filter_public(self):
        request = async_mock.MagicMock()
        request.app = self.app
        request.query = {"public": "true"}
        with async_mock.patch.object(
            test_module.web, "json_response", async_mock.Mock()
        ) as json_response, async_mock.patch.object(
            test_module, "format_did_info", async_mock.Mock()
        ) as format_did_info:
            self.wallet.get_public_did.return_value = DIDInfo(
                self.test_did, self.test_verkey, {}
            )
            format_did_info.return_value = {"did": self.test_did}
            result = await test_module.wallet_did_list(request)
            format_did_info.assert_called_once_with(
                self.wallet.get_public_did.return_value
            )
            json_response.assert_called_once_with(
                {"results": [format_did_info.return_value]}
            )
            assert json_response.return_value is json_response()
            assert result is json_response.return_value 
开发者ID:hyperledger,项目名称:aries-cloudagent-python,代码行数:24,代码来源:test_routes.py


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