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


Python Mock.create方法代码示例

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


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

示例1: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
 def setUp(self):
     """setUp for all unit tests in this class"""
     interactor_factory = Mock(factory.InteractorFactory)
     self.__interactor = Mock(hi.AddHardwareTypeInteractor)
     interactor_factory.create = Mock(return_value=self.__interactor)
     self.__target = ath.AddHardwareTypeHandler(interactor_factory, None)
     self.__target.session = Mock(session.Session)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:9,代码来源:TestAddHardwareTypeHandler.py

示例2: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
    def setUp(self):
        """setUp function for all unit tests in this class"""
        
        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

        self.__games = [Game()]
        self.__hardware = [Hardware()]
        self.__renderer = Mock(TemplateRenderer)

        get_interactors = lambda: [get_interactor(game_interactors.GetGamesInteractor), 
                                   get_interactor(hardware_interactors.GetHardwareListInteractor),
                                   get_interactor(game_interactors.CountGamesInteractor),
                                   get_interactor(hardware_interactors.CountHardwareInteractor)]

        interactor_factory = Mock(InteractorFactory)
        interactor_factory.create = Mock(side_effect=get_interactors())
        self.__config = Mock(Config)
        self.__config.get = Mock(return_value=0)
        self.__target = IndexHandler(interactor_factory, self.__renderer, self.__config)
        self.__target.session = Mock(Session)
        self.__get_page = lambda args: self.__target.get_page(args)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:34,代码来源:TestIndexHandler.py

示例3: setUp

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

        def init_games():
            game_data = [{'title': 'game1',
                          'platform': 'platform1'},
                         {'title': 'game2',
                          'platform': 'platform2'}]
            return [g.Game.from_dict(d) for d in game_data]

        def init_hardware():
            hardware_data = [{'title': 'game1',
                            'platform': 'platform1'},
                            {'title': 'game2',
                             'platform': 'platform2'}]
            return [h.Hardware.from_dict(d) for d in hardware_data]

        self.__games = init_games()
        self.__hardware = init_hardware()

        self.__get_games_interactor = Mock(gi.GetGamesInteractor)
        self.__get_games_interactor.execute = Mock(return_value=self.__games)

        self.__hardware_list_interactor = Mock(hi.GetHardwareListInteractor)
        self.__hardware_list_interactor.execute = Mock(return_value=self.__hardware)

        def interactor_factory_create(interactor_type):
            interactors = {'GetGamesInteractor': self.__get_games_interactor,
                           'GetHardwareListInteractor': self.__hardware_list_interactor}

            return interactors[interactor_type]

        factory = Mock(interactor_factory.InteractorFactory)
        factory.create = Mock(side_effect=interactor_factory_create)
        self.__target = ci.ExportCollectionInteractor(factory) 
开发者ID:jeroanan,项目名称:GameCollection,代码行数:36,代码来源:TestCollectionInteractors.py

示例4: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
 def setUp(self):
     """setUp method for all unit tests in this class"""
     interactor_factory = Mock(factory.InteractorFactory)
     self.__interactor = Mock(pi.AddPlatformInteractor)
     interactor_factory.create = Mock(return_value=self.__interactor)
     self.__target = aph.AddPlatformHandler(interactor_factory, renderer=None)
     self.__target.session = Mock(sess.Session) 
开发者ID:jeroanan,项目名称:GameCollection,代码行数:9,代码来源:TestAddPlatformHandler.py

示例5: setUp

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

        def interactor_factory_create(interactor_type):
            """Mock function for InteractorFactory.Create"""
            interactors = {"GetHardwareDetailsInteractor": (hi.GetHardwareDetailsInteractor, self.__hardware),
                           "GetPlatformsInteractor": (pi.GetPlatformsInteractor, self.__platforms),
                           "GetHardwareTypeListInteractor": (hi.GetHardwareTypeListInteractor, self.__hardware_types)}

            if interactor_type in interactors:
                interactor_type, data = interactors[interactor_type]
                interactor = Mock(interactor_type)
                interactor.execute = Mock(return_value=data)
                return interactor

        self.__hardware = h.Hardware()
        self.__platforms = [p.Platform()]
        self.__hardware_types = [ht.HardwareType()]

        interactor_factory = Mock(factory.InteractorFactory)
        interactor_factory.create = Mock(side_effect=interactor_factory_create)

        self.__renderer = Mock(renderer.TemplateRenderer)
        self.__target = ehh.EditHardwareHandler(interactor_factory, self.__renderer)
        self.__target.session = Mock(sess.Session)
        args = {"hardwareid": "hardwareid"}
        self.__get_page = lambda: self.__target.get_page(args)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:29,代码来源:TestEditHardwareHandler.py

示例6: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
    def setUp(self):
        def get_games_data():
            games_data = [{'title': 'title1',
                          'platform': 'platform1'},
                          {'title': 'title2',
                           'platform': 'platform2'}]
            return [g.Game.from_dict(d) for d in games_data]

        def get_hardware_data():
            hardware_data = [{'name': 'hardware1',
                              'platform': 'platform1'},
                             {'name': 'hardware2',
                              'platform': 'platform2'}]
            return [h.Hardware.from_dict(d) for d in hardware_data]

        self.__interactor = Mock(ci.ExportCollectionInteractor)
        self.__interactor.execute = Mock(return_value={'games': get_games_data(),
                                                       'hardware': get_hardware_data()})

        self.__games_data = get_games_data()
        self.__hardware_data = get_hardware_data()
        
        self.__user_id = "user"

        interactor_factory = Mock(factory.InteractorFactory)
        interactor_factory.create = Mock(return_value=self.__interactor)

        self.__target = geh.GetExportHandler(interactor_factory, None)

        self.__session = Mock(sess.Session)
        self.__session.get_value = Mock(return_value=self.__user_id)

        self.__target.session = self.__session
开发者ID:jeroanan,项目名称:GameCollection,代码行数:35,代码来源:TestGetExportHandler.py

示例7: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
    def setUp(self):
        """setUp for all unit tests in this class"""
        self.__stored_hardware_types = [ht.HardwareType.from_dict({"name": "type1"})]
        self.__suggested_hardware_types = [ht.HardwareType.from_dict({"name": "type2"})]

        def create_interactor(interactor_type):
            """Mock for InteractorFactory.create"""
            interactor = None

            interactors = {
                "GetHardwareTypeListInteractor": (hi.GetHardwareTypeListInteractor, self.__stored_hardware_types),
                "GetSuggestedHardwareTypesInteractor": (hi.GetSuggestedHardwareTypesInteractor, self.__suggested_hardware_types)
            }

            if interactor_type in interactors:
                interactor_type, data = interactors[interactor_type]
                interactor = Mock(interactor_type)
                interactor.execute = Mock(return_value=data)

            return interactor

        factory = Mock(interactor_factory.InteractorFactory)        
        factory.create = Mock(side_effect=create_interactor)
        self.__renderer = Mock(tr.TemplateRenderer)

        self.__target = hth.HardwareTypesHandler(factory, self.__renderer)
        self.__target.session = Mock(session.Session)        
开发者ID:jeroanan,项目名称:GameCollection,代码行数:29,代码来源:TestHardwareTypesHandler.py

示例8: setUp

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

        def interactor_factory_create(interactor_type):

            def create_get_genres_interactor():
                get_genres_interactor = Mock(gi.GetGenresInteractor)
                get_genres_interactor.execute = Mock(return_value=self.__genres)
                return get_genres_interactor

            def create_get_suggested_genres_interactor():
                get_genres_interactor = Mock(gi.GetSuggestedGenresInteractor)
                get_genres_interactor.execute = Mock(return_value=self.__suggested_genres)
                return get_genres_interactor

            if interactor_type == "GetGenresInteractor":
                return create_get_genres_interactor()
            elif interactor_type == "GetSuggestedGenresInteractor":
                return create_get_suggested_genres_interactor()

        self.__genres = [g.Genre.from_dict({"name": "stored genre"})]
        self.__suggested_genres = [g.Genre.from_dict({"name": "suggested genre"})]
        interactor_factory = Mock(ifactory.InteractorFactory)        
        interactor_factory.create = Mock(side_effect=interactor_factory_create)
        self.__renderer = Mock(tr.TemplateRenderer)
        self.__target = gh.GenresHandler(interactor_factory, self.__renderer)
        self.__target.session = Mock(session.Session)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:29,代码来源:TestGenresHandler.py

示例9: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
 def setUp(self):
     """setup function for all unit tests in this class."""
     self.__interactor = Mock(pi.DeletePlatformInteractor)
     interactor_factory = Mock(factory.InteractorFactory)
     interactor_factory.create = Mock(return_value=self.__interactor)
     self.__target = dph.DeletePlatformHandler(interactor_factory, None)
     self.__target.session = Mock(sess.Session)
     self.__get_params = lambda: {"id": "id"}
开发者ID:jeroanan,项目名称:GameCollection,代码行数:10,代码来源:TestDeletePlatformHandler.py

示例10: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
 def setUp(self):
     """setUp for all unit tests in this class"""
     interactor_factory = Mock(factory.InteractorFactory)
     self.__interactor = Mock(hi.UpdateHardwareTypeInteractor)
     interactor_factory.create = Mock(return_value=self.__interactor)
     self.__target = handler.UpdateHardwareTypeHandler(interactor_factory, None)
     self.__target.session = Mock(session.Session)
     self.__required_params = ['id', 'name']
开发者ID:jeroanan,项目名称:GameCollection,代码行数:10,代码来源:TestUpdateHardwareTypeHandler.py

示例11: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [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

示例12: __setUp_interactor_factory

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
    def __setUp_interactor_factory(self):
        
        def interactor_factory_create(interactor_type):
            return self.__get_user_interactor

        interactor_factory = Mock(InteractorFactory)
        interactor_factory.create = Mock(side_effect=interactor_factory_create)
        return interactor_factory
开发者ID:jeroanan,项目名称:GameCollection,代码行数:10,代码来源:TestChangePasswordInteractor.py

示例13: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [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

示例14: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
 def setUp(self):
     """setUp function for all unit tests in this class"""
     self.__interactor = Mock(hi.DeleteHardwareInteractor)
     interactor_factory = Mock(factory.InteractorFactory)
     interactor_factory.create = Mock(return_value=self.__interactor)
     self.__target = dhh.DeleteHardwareHandler(interactor_factory, None)
     self.__target.session = Mock(sess.Session)
     self.__get_args = lambda: {"id": "hardwareid"}
     self.__missing_param_returns_empty_string = hta.get_missing_param_assertion(self.__target)
     self.__empty_param_returns_empty_string = hta.get_empty_param_assertion(self.__target)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:12,代码来源:TestDeleteHardwareHandler.py

示例15: setUp

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import create [as 别名]
 def setUp(self):
     """setUp function for all unit tests in this class"""
     self.__interactor = Mock(DeleteUserInteractor)
     interactor_factory = Mock(InteractorFactory)
     interactor_factory.create = Mock(return_value=self.__interactor)
     self.__target = DeleteUserHandler(interactor_factory, None)
     self.__target.session = Mock(Session)
     params = {"id": "id"}
     self.__user = User.from_dict(params)
     self.__get_page = lambda: self.__target.get_page(params)
开发者ID:jeroanan,项目名称:GameCollection,代码行数:12,代码来源:TestDeleteUserHandler.py


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