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


Python MagicMock.get方法代码示例

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


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

示例1: test_remove_watcher_view_removes_observer_from_item

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
    def test_remove_watcher_view_removes_observer_from_item(self, notifications):
        decision = N(Decision)
        user = N(User)

        mock_view = MagicMock(spec=RemoveWatcher)
        mock_view.get_object = lambda: decision
        mock_view.get_user = lambda: user
        mock_view.get = RemoveWatcher.get

        mock_view.get(mock_view, RequestFactory().get('/', {'next': '/'}))
        notifications.stop_observing.assert_called_with(decision, user)
开发者ID:JayFliz,项目名称:econsensus,代码行数:13,代码来源:watcher_view_test.py

示例2: test_add_watcher_view_adds_observer_to_item

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
    def test_add_watcher_view_adds_observer_to_item(self, notifications):
        decision = N(Decision)
        user = N(User)

        mock_view = MagicMock(spec=AddWatcher)
        mock_view.get_object = lambda: decision
        mock_view.get_user = lambda: user
        mock_view.get = AddWatcher.get

        mock_view.get(mock_view, RequestFactory().get('/', {'next': '/'}))
        notifications.observe.assert_called_with(
            decision, user, DECISION_CHANGE)
开发者ID:hhsw2,项目名称:econsensus,代码行数:14,代码来源:watcher_view_test.py

示例3: test_last_message_user

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
    def test_last_message_user(self):
        context_data = MagicMock()
        context_data.get = MagicMock(return_value="existing_context_value")
        attribute_product_data = MagicMock()

        target = Target(context_data, attribute_product_data)
        target.extract_last_user_message = MagicMock(return_value="last_message")
        target.extract_entities = MagicMock(return_value="extracted_entities")
        target.remove_default_entities_if_detections = MagicMock(return_value="removed_entities")
        target.update_entities_with_last_message = MagicMock(return_value="entities_update_entities_with_last_message")
        target.create_entity_type_index_modifier = MagicMock(return_value="entities_create_entity_type_index_modifier")
        target.change_entities_weighting = MagicMock(return_value="entities_change_entities_weighting")

        target.add_product_counts = MagicMock(return_value="entities_add_product_counts")
        target.split_unsupported_entities = MagicMock(return_value=("supported_entities", "unsupported_entities"))

        target.update("context_id_value", "_rev_value", "messages_value")

        target.extract_last_user_message.assert_called_once_with("messages_value")
        context_data.get.assert_called_once_with("context_id_value", "_rev_value")
        target.extract_entities.assert_called_once_with("existing_context_value")
        target.update_entities_with_last_message.assert_called_once_with("extracted_entities", "last_message")
        target.remove_default_entities_if_detections.assert_called_once_with(
            "entities_update_entities_with_last_message"
        )
        target.create_entity_type_index_modifier.assert_called_once_with("removed_entities")
        target.change_entities_weighting.assert_called_once_with("entities_create_entity_type_index_modifier")
        target.add_product_counts.assert_called_once_with("entities_change_entities_weighting")
        target.split_unsupported_entities.assert_called_once_with("entities_add_product_counts")
        context_data.update.assert_called_once_with(
            "context_id_value", "_rev_value", unsupported_entities="unsupported_entities", entities="supported_entities"
        )
开发者ID:rdefeo,项目名称:context,代码行数:34,代码来源:test_contextualizer_Contextualizer.py

示例4: test_archive_cannot_be_found

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
def test_archive_cannot_be_found(job_mock, registry_mock, connection_mock):
    conn_s3 = boto.connect_s3()
    storage = conn_s3.create_bucket('storage-bucket')
    conn_s3.create_bucket('file-bucket')

    registry = MagicMock()
    registry.get = MagicMock(side_effect=side_effect)

    registry_mock.return_value = registry

    message = Message()
    message.set_body(json.dumps({
        'Message': '9bd96ca7-3d0a-4e74-b523-b3bd38e9862e',
        'Subject': 'Test Subject'
    }))

    job = MagicMock(**{
        'uuid': '9bd96ca7-3d0a-4e74-b523-b3bd38e9862e',
        'name': 'Migration Download',
        'status': 'pending',
        'message': {
            'file': {
                'key': 'archive.zip'
            }
        }
    })

    job_mock.selectBy.return_value.getOne.return_value = job

    service = MigrationUploadJob()
    with pytest.raises(InvalidJobError):
        service.do_work(message)

    assert job.set.called
开发者ID:pmcilwaine,项目名称:hermes,代码行数:36,代码来源:migration_upload_test.py

示例5: test_do_work

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
def test_do_work(job_mock, registry_mock):

    conn = boto.sns.connect_to_region('ap-southeast-2')
    topic = conn.create_topic('multipage-test')

    def side_effect(value):
        return {
            'topics': {'topic': {'multipage': topic['CreateTopicResponse']['CreateTopicResult']['TopicArn']}},
            'region': {'region': 'ap-southeast-2'}
        }.get(value)

    registry = MagicMock()
    registry.get = MagicMock(side_effect=side_effect)
    registry_mock.return_value = registry

    document = MagicMock(**{
        'uuid': 'some-id',
        'published': True
    })
    document.name = 'Test Document'

    job_mock.save.return_value = MagicMock(**{
        'uuid': 'job-id'
    })

    helper = Multipage(document)
    helper.do_work()

    assert document.set.called
    assert job_mock.save.called
开发者ID:pmcilwaine,项目名称:hermes,代码行数:32,代码来源:multipage_test.py

示例6: test_no_current_value_add_a_list

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
    def test_no_current_value_add_a_list(self):
        """
        update_invalid_media_paths should be able to cope with when the old value is empty and the new is a list
        :return:
        """
        from asset_folder_importer.database import importer_db
        from gnmvidispine.vs_collection import VSCollection
        from gnmvidispine.vidispine_api import VSNotFound
        from gnmvidispine.vs_item import VSItem
        from asset_folder_importer.premiere_get_referenced_media.PremiereProject import PremiereProject
        mock_database = MagicMock(target=importer_db)

        mock_coll_instance = MagicMock(target=VSCollection)
        mock_proj_instance = MagicMock(target=PremiereProject)
        mock_item_instance = MagicMock(target=VSItem)
        mock_proj_instance.getReferencedMedia = MagicMock(return_value=['/Volumes/Internet Downloads/WRONG FILE.mov'])
        mock_coll_instance.get = MagicMock(return_value=[])
        with patch('asset_folder_importer.premiere_get_referenced_media.processor.VSCollection', return_value=mock_coll_instance) as mock_coll:
            with patch('asset_folder_importer.premiere_get_referenced_media.processor.VSItem', return_value=mock_item_instance):
                with patch('asset_folder_importer.premiere_get_referenced_media.processor.PremiereProject', return_value=mock_proj_instance) as mock_proj:
                    with patch('asset_folder_importer.premiere_get_referenced_media.processor.process_premiere_fileref',side_effect=VSNotFound()):
                        from asset_folder_importer.premiere_get_referenced_media.processor import process_premiere_project

                        process_premiere_project("/fakeproject/VX-446.prproj", None, db=mock_database, cfg=self.FakeConfig())
                        mock_coll_instance.get.assert_called()
                        mock_coll_instance.set_metadata.assert_called_with({'gnm_project_invalid_media_paths': ['/Volumes/Internet Downloads/WRONG FILE.mov']},mode="add")
开发者ID:guardian,项目名称:assetsweeper,代码行数:28,代码来源:test_premiere_processor.py

示例7: test_notify_wrongpath

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
    def test_notify_wrongpath(self):
        """
        process_premiere_project should update project record with any non-SAN media paths
        :return:
        """
        from asset_folder_importer.database import importer_db
        from gnmvidispine.vs_collection import VSCollection
        from gnmvidispine.vidispine_api import VSNotFound
        from gnmvidispine.vs_item import VSItem
        from asset_folder_importer.premiere_get_referenced_media.PremiereProject import PremiereProject
        mock_database = MagicMock(target=importer_db)

        #with patch('asset_folder_importer.premiere_get_referenced_media.processor.VSCollection') as mock_coll:
        mock_coll_instance = MagicMock(target=VSCollection)
        mock_proj_instance = MagicMock(target=PremiereProject)
        mock_item_instance = MagicMock(target=VSItem)
        mock_proj_instance.getReferencedMedia = MagicMock(return_value=['/Volumes/Internet Downloads/WRONG FILE.mov'])
        mock_coll_instance.get = MagicMock(return_value=None)
        with patch('asset_folder_importer.premiere_get_referenced_media.processor.VSCollection', return_value=mock_coll_instance) as mock_coll:
            with patch('asset_folder_importer.premiere_get_referenced_media.processor.VSItem', return_value=mock_item_instance):
                with patch('asset_folder_importer.premiere_get_referenced_media.processor.PremiereProject', return_value=mock_proj_instance) as mock_proj:
                    with patch('asset_folder_importer.premiere_get_referenced_media.processor.process_premiere_fileref',side_effect=VSNotFound()):
                        from asset_folder_importer.premiere_get_referenced_media.processor import process_premiere_project

                        process_premiere_project("/fakeproject/VX-446.prproj", None, db=mock_database, cfg=self.FakeConfig())
                        mock_coll_instance.set_metadata.assert_called_with({'gnm_project_invalid_media_paths': ['/Volumes/Internet Downloads/WRONG FILE.mov']},mode="add")
开发者ID:guardian,项目名称:assetsweeper,代码行数:28,代码来源:test_premiere_processor.py

示例8: test_add_watcher_view_adds_observer_to_item

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
    def test_add_watcher_view_adds_observer_to_item(self, notifications):
        # A watcher is only added if the item isn't already being watched so we
        # explicitly set is_observing to False
        notifications.is_observing = lambda decision, user: False

        decision = N(Decision)
        user = N(User)

        mock_view = MagicMock(spec=AddWatcher)
        mock_view.get_object = lambda: decision
        mock_view.get_user = lambda: user
        mock_view.get = AddWatcher.get

        mock_view.get(mock_view, RequestFactory().get('/', {'next': '/'}))
        notifications.observe.assert_called_with(
            decision, user, DECISION_CHANGE)
开发者ID:JayFliz,项目名称:econsensus,代码行数:18,代码来源:watcher_view_test.py

示例9: test_solve_conflicts_both_update_a_file

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
    def test_solve_conflicts_both_update_a_file(self):
        mocked_theirs = MagicMock()
        mocked_ours = MagicMock(id="id", path="path")
        mocked_full = MagicMock(return_value="full_path")
        mocked_repo = MagicMock(_full_path=mocked_full)

        mocked_repo.get().data = "data"

        def conflicts():
            yield None, mocked_theirs, mocked_ours

        mock_path = 'gitfs.merges.accept_mine.open'
        with patch(mock_path, create=True) as mocked_open:
            mocked_file = MagicMock(spec=file)
            mocked_open.return_value = mocked_file

            mine = AcceptMine(mocked_repo)

            mine.solve_conflicts(conflicts())

            mocked_full.assert_called_once_with("path")
            mocked_open.assert_called_once_with("full_path", "w")
            mocked_repo.get.has_calls([call("id")])
            mocked_open().__enter__().write.assert_called_once_with("data")
            mocked_repo.index.add.assert_called_once_with("path")
开发者ID:AlexSnet,项目名称:gitfs,代码行数:27,代码来源:test_accept_mine.py

示例10: test_caching_is_per_instance

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
def test_caching_is_per_instance():
    # Test that values cached for one instance do not appear on another
    class FieldTester(ScopedStorageMixin):
        """Toy class for ModelMetaclass and field access testing"""
        field_a = List(scope=Scope.settings)

    field_data = MagicMock(spec=FieldData)
    field_data.get = lambda block, name, default=None: [name]  # pylint: disable=C0322

    # Same field_data used in different objects should result
    # in separately-cached values, so that changing a value
    # in one instance doesn't affect values stored in others.
    field_tester_a = FieldTester(
        runtime=TestRuntime(services={'field-data': field_data}),
        scope_ids=MagicMock(spec=ScopeIds)
    )
    field_tester_b = FieldTester(
        runtime=TestRuntime(services={'field-data': field_data}),
        scope_ids=MagicMock(spec=ScopeIds)
    )
    value = field_tester_a.field_a
    assert_equals(value, field_tester_a.field_a)
    field_tester_a.field_a.append(1)
    assert_equals(value, field_tester_a.field_a)
    assert_not_equals(value, field_tester_b.field_a)
开发者ID:Keeward,项目名称:XBlock,代码行数:27,代码来源:test_core.py

示例11: test_get

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
    def test_get(self):
        """
        Test that we can get data from files.  Verify that the driver
        sampling can be started and stopped
        """
        from mi.core.kudu.brttpkt import NoData
        rvals = [(self.PKT_ID, sn, ts, pkt) for (pt, pkt, sn, ts) in [
                        makepacket(self.PKT_DATA, time=n+1) for n in range(2)]]
        def orbget():
            if rvals:
                log.trace('returning 1st packet')
                return rvals.pop(0)
            else:
                log.trace('no more packets')
                raise NoData()
        with patch('mi.dataset.parser.antelope_orb.OrbReapThr') as MockOrbReapThr:
            orbreapthr = MagicMock()
            orbreapthr.get = orbget
            MockOrbReapThr.return_value = orbreapthr
            self.driver.start_sampling()

        log.trace("STARTED SAMPLING")

        self.assert_data(None, 'first.result.yml', count=2, timeout=5)
        log.trace("ASSERTED DATA")
开发者ID:JeffRoy,项目名称:marine-integrations,代码行数:27,代码来源:test_driver.py

示例12: setUp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
    def setUp(self):
        super(SolrMockupTestCase, self).setUp()
        assert self.schema is not None, 'A path for Solr schema is needed'
        conn = MagicMock(name='SolrConnection')
        conn.get = MagicMock(
            name='get',
            return_value=SolrResponse(
                body=self.schema,
                status=200,
            ))

        manager = MagicMock(name='SolrConnectionManager')
        manager.connection = conn
        manager.schema = SolrSchema(manager)

        solr = getUtility(ISolrSearch)
        solr._manager = manager

        assert self.search is not None, 'A path for Solr search is needed'
        solr.search = MagicMock(
            name='search',
            return_value=SolrResponse(
                body=self.search,
                status=200,
            ))
        self.solr = solr
        self.source = UsersContactsInboxesSource(self.portal)
开发者ID:lukasgraf,项目名称:opengever.core,代码行数:29,代码来源:test_sources.py

示例13: test_object_identity

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
def test_object_identity():
    # Check that values that are modified are what is returned
    class FieldTester(ScopedStorageMixin):
        """Toy class for ModelMetaclass and field access testing"""
        field_a = List(scope=Scope.settings)

    # Make sure that field_data always returns a different object
    # each time it's actually queried, so that the caching is
    # doing the work to maintain object identity.
    field_data = MagicMock(spec=FieldData)
    field_data.get = lambda block, name, default=None: [name]  # pylint: disable=C0322
    field_tester = FieldTester(
        runtime=TestRuntime(services={'field-data': field_data}),
        scope_ids=MagicMock(spec=ScopeIds)
    )

    value = field_tester.field_a
    assert_equals(value, field_tester.field_a)

    # Changing the field in place matches a previously fetched value
    field_tester.field_a.append(1)
    assert_equals(value, field_tester.field_a)

    # Changing the previously-fetched value also changes the value returned by the field:
    value.append(2)
    assert_equals(value, field_tester.field_a)

    # Deletion restores the default value.  In the case of a List with
    # no default defined, this is the empty list.
    del field_tester.field_a
    assert_equals([], field_tester.field_a)
开发者ID:Keeward,项目名称:XBlock,代码行数:33,代码来源:test_core.py

示例14: should_call_twice

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
        def should_call_twice(self, topic):

            def callback(*args, **kwargs):
                pass

            file_key = {
                'Error': 'Error',
                'ResponseMetadata': {
                    'HTTPStatusCode': 502
                }
            }

            self.call_count = 0
            def get(key, callback=None):
                self.call_count += 1
                callback(file_key)

            mock_bucket_loader = MagicMock()
            mock_bucket_loader.get = get
            func = s3_loader.HandleDataFunc.as_func(
                '/'.join([s3_bucket, IMAGE_PATH]),
                callback=callback,
                bucket_loader=mock_bucket_loader,
                context=topic
            )

            func(file_key)
            expect(self.call_count).to_equal(3)
开发者ID:aoqfonseca,项目名称:aws,代码行数:30,代码来源:s3_loader_vows.py

示例15: test_caching_is_per_instance

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import get [as 别名]
def test_caching_is_per_instance():
    # Test that values cached for one instance do not appear on another
    class FieldTester(object):
        """Toy class for ModelMetaclass and field access testing"""
        __metaclass__ = ModelMetaclass

        field_a = List(scope=Scope.settings)

        def __init__(self, field_data):
            self._field_data = field_data
            self._dirty_fields = {}

    field_data = MagicMock(spec=FieldData)
    field_data.get = lambda block, name, default=None: [name]  # pylint: disable=C0322

    # Same field_data used in different objects should result
    # in separately-cached values, so that changing a value
    # in one instance doesn't affect values stored in others.
    field_tester_a = FieldTester(field_data)
    field_tester_b = FieldTester(field_data)
    value = field_tester_a.field_a
    assert_equals(value, field_tester_a.field_a)
    field_tester_a.field_a.append(1)
    assert_equals(value, field_tester_a.field_a)
    assert_not_equals(value, field_tester_b.field_a)
开发者ID:renzo-orsini,项目名称:XBlock,代码行数:27,代码来源:test_core.py


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