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


Python Mock.execute方法代码示例

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


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

示例1: __setUp_get_user_interactor

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
    def __setUp_get_user_interactor(self):

        def get_user_interactor_execute(user):
            return self.__get_user(user_id=user.user_id, password="MyOldPassword", id="123456")

        get_user_interactor = Mock(GetUserInteractor)
        get_user_interactor.execute = Mock(side_effect=get_user_interactor_execute)
        return get_user_interactor
开发者ID:jeroanan,项目名称:GameCollection,代码行数:10,代码来源:TestChangePasswordInteractor.py

示例2: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
 def setUp(self):
     interactor = Mock(SearchInteractor())
     interactor.execute = Mock(return_value=[])
     interactor_factory = Mock(InteractorFactory)
     interactor_factory.create = Mock(return_value=interactor)
     self.__renderer = Mock(TemplateRenderer)
     self.__target = SearchHandler(interactor_factory, self.__renderer)
     self.__target.session = Mock(Session)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:10,代码来源:TestSearchHandler.py

示例3: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
    def setUp(self):
        """setUp function for all unit tests in this class"""

        def interactor_factory_create():
            return [get_platforms_interactor, get_suggested_platforms_interactor]

        self.__platforms = [Platform()]
        self.__suggested_platforms = [Platform(), Platform()]
        get_platforms_interactor = Mock(GetPlatformsInteractor)
        get_platforms_interactor.execute = Mock(return_value=self.__platforms)
        get_suggested_platforms_interactor = Mock(GetSuggestedPlatformsInteractor)
        get_suggested_platforms_interactor.execute = Mock(return_value=self.__suggested_platforms)
        interactor_factory = Mock(InteractorFactory)
        interactor_factory.create = Mock(side_effect=interactor_factory_create())
        self.__renderer = Mock(TemplateRenderer)
        self.__target = PlatformsHandler(interactor_factory, self.__renderer)
        session = Mock(Session)
        self.__target.session = session
开发者ID:jeroanan,项目名称:GameCollection,代码行数:20,代码来源:TestPlatformsHandler.py

示例4: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
 def setUp(self):
     """setUp function for all unit tests in this class"""
     self.__users = [User()]
     interactor = Mock(GetUsersInteractor)
     interactor.execute = Mock(return_value=self.__users)
     interactor_factory = Mock(InteractorFactory)
     interactor_factory.create = Mock(return_value=interactor)
     self.__renderer = Mock(TemplateRenderer)
     self.__target = UsersHandler(interactor_factory, self.__renderer)
     self.__target.session = Mock(Session)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:12,代码来源:TestUsersHandler.py

示例5: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
 def setUp(self):
     """setUp function for all unit tests in this class"""
     self.__hardware = [Hardware()]
     interactor = Mock(GetHardwareListInteractor)
     interactor.execute = Mock(return_value=self.__hardware)
     interactor_factory = Mock(InteractorFactory)
     interactor_factory.create = Mock(return_value=interactor)
     self.__renderer = Mock(TemplateRenderer)
     self.__target = SortHardwareHandler(interactor_factory, self.__renderer)
     self.__target.session = Mock(Session)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:12,代码来源:TestSortHardwareHandler.py

示例6: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
 def setUp(self):
     self.__params = {"name": "n", "description": "d"}
     self.__hardware_type = ht.HardwareType.from_dict(self.__params)
     interactor = Mock(hi.GetHardwareTypeInteractor)
     interactor.execute = Mock(return_value=self.__hardware_type)
     interactor_factory = Mock(factory.InteractorFactory)
     interactor_factory.create = Mock(return_value=interactor)
     self.__renderer = Mock(renderer.TemplateRenderer)
     self.__target = ehth.EditHardwareTypeHandler(interactor_factory, self.__renderer)
     self.__target.session = Mock(session.Session)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:12,代码来源:TestEditHardwareTypeHandler.py

示例7: interactor_factory_create

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
        def interactor_factory_create(interactor_type):
            """Mock function for InteractorFactory.create"""

            interactors = {"GetPlatformsInteractor": (pi.GetPlatformsInteractor, self.__platforms),
                           "GetHardwareTypeListInteractor": (hi.GetHardwareTypeListInteractor, self.__hardware_types)}

            if interactor_type in interactors:
                interactor_class, data = interactors[interactor_type]
                interactor = Mock(interactor_class)
                interactor.execute = Mock(return_value=data)
                return interactor
开发者ID:jeroanan,项目名称:GameCollection,代码行数:13,代码来源:TestAddHardwareHandler.py

示例8: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
 def setUp(self):
     """setUp for all unit tests in this class"""
     self.__game = g.Game.from_dict({"id": "myid", "title": "my title"})
     get_game_interactor = Mock(gi.GetGameInteractor)
     get_game_interactor.execute = Mock(return_value=self.__game)
     interactor_factory = Mock(factory.InteractorFactory)
     interactor_factory.create = Mock(return_value=get_game_interactor)
     self.__renderer = Mock(tr.TemplateRenderer)
     self.__target = vgh.ViewGameHandler(interactor_factory, self.__renderer)
     self.__target.session = Mock(sess.Session)
     self.__target.session.get_value = Mock(return_value="1234")
开发者ID:jeroanan,项目名称:GameCollection,代码行数:13,代码来源:TestViewGameHandler.py

示例9: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
 def setUp(self):
     """setUp function for all unit tests in this class"""
     interactor = Mock(GetGamesInteractor)
     self.__games = [Game()]
     interactor.execute = Mock(return_value=self.__games)
     interactor_factory = Mock(InteractorFactory)
     interactor_factory.create = Mock(return_value=interactor)
     self.__renderer = Mock(TemplateRenderer)
     self.__target = SortGamesHandler(interactor_factory, self.__renderer)
     self.__target.session = Mock(Session)
     self.__get_args = lambda: {"field": "title", "sortdir": "asc", "numrows": 2}
开发者ID:jeroanan,项目名称:GameCollection,代码行数:13,代码来源:TestSortGamesHandler.py

示例10: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
 def setUp(self):
     super().setUp()
     self.__games = [Game()]
     interactor = Mock(GetGamesInteractor)
     interactor.execute = Mock(return_value=self.__games)
     interactor_factory = Mock(InteractorFactory)
     interactor_factory.create = Mock(return_value=interactor)
     self.__renderer = Mock(TemplateRenderer)
     self.__target = AllGamesHandler(interactor_factory, self.__renderer)
     self.__target.session = Mock(Session)
     self.__get_page = lambda: self.__target.get_page(self.__get_params())
开发者ID:jeroanan,项目名称:GameCollection,代码行数:13,代码来源:TestAllGamesHandler.py

示例11: get_interactor

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
            def get_interactor(interactor_type):                
                interactors = {"GetGameInteractor": (gi.GetGameInteractor, self.__game),
                               "GetPlatformsInteractor": (pi.GetPlatformsInteractor, self.__platforms),
                               "GetGenresInteractor": (gei.GetGenreInteractor, self.__genres)}

                if interactor_type not in interactors: 
                    return None

                t, data = interactors[interactor_type]
                i = Mock(t)
                i.execute = Mock(return_value=data)
                return i
开发者ID:jeroanan,项目名称:GameCollection,代码行数:14,代码来源:TestEditGameHandler.py

示例12: get_interactor

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
 def get_interactor(interactor_type):
     interactors = {game_interactors.GetGamesInteractor: self.__games,
                    game_interactors.CountGamesInteractor: 0,
                    hardware_interactors.GetHardwareListInteractor: self.__hardware,
                    hardware_interactors.CountHardwareInteractor: 2
     }
     
     if interactor_type in interactors:
         interactor = Mock(interactor_type)
         interactor.execute = Mock(return_value=interactors[interactor_type])
         return interactor
     return None
开发者ID:jeroanan,项目名称:GameCollection,代码行数:14,代码来源:TestIndexHandler.py

示例13: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
 def setUp(self):        
     """setUp function for all unit tests in this class"""
     get_params = lambda genre_id="id": {"genreid": genre_id}
     self.__get_page = lambda: self.__target.get_page(get_params())
     self.__genre = Genre.from_dict(get_params())
     interactor_factory = Mock(InteractorFactory)
     interactor = Mock(GetGenreInteractor)
     interactor.execute = Mock(return_value=self.__genre)
     interactor_factory.create = Mock(return_value=interactor)
     self.__renderer = Mock(TemplateRenderer)
     self.__target = EditGenreHandler(interactor_factory, self.__renderer)
     self.__target.session = Mock(Session)        
开发者ID:jeroanan,项目名称:GameCollection,代码行数:14,代码来源:TestEditGenreHandler.py

示例14: init_target

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
        def init_target():
            def update_game(game, user_id):
                raise PersistenceException

            p = Mock(AbstractPersistence)
            interactor = Mock(UpdateGameInteractor)
            interactor.execute = Mock(side_effect=update_game)
            interactor_factory = Mock(InteractorFactory)
            interactor_factory.create = Mock(return_value=interactor)
            target = UpdateGameHandler(interactor_factory, Mock(TemplateRenderer))
            target.session = Mock(Session)
            return target
开发者ID:jeroanan,项目名称:GameCollection,代码行数:14,代码来源:TestUpdateGameHandler.py

示例15: test_interactor_raises_exception_returns_empty_string

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import execute [as 别名]
    def test_interactor_raises_exception_returns_empty_string(self):
        """Test that if DeleteHardwareInteractor.execute raises an exception then DeleteHardwareHandler.get_page 
        returns an empty string"""
        def boom(hardware_id, user_id):
            raise Exception("ouch!")
        
        interactor = Mock(hi.DeleteHardwareInteractor)
        interactor.execute = Mock(side_effect=boom)
        interactor_factory = Mock(factory.InteractorFactory)
        interactor_factory.create = Mock(return_value=interactor)
        self.__target = dhh.DeleteHardwareHandler(interactor_factory, None)
        self.__target.session = Mock(sess.Session)

        result = self.__target.get_page(self.__get_args())
        self.assertEqual("", result)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:17,代码来源:TestDeleteHardwareHandler.py


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