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


Python MagicMock.projection方法代码示例

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


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

示例1: test_filters_out_all_but_whitelisted_fields_if_requested

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import projection [as 别名]
    def test_filters_out_all_but_whitelisted_fields_if_requested(self):
        request = MagicMock()
        request.args = MultiDict([('include_fields', 'body_text,byline')])
        request.projection = None

        instance = self._make_one()
        instance._set_fields_filter(request)

        projection = json.loads(request.projection) if request.projection else {}
        expected_projection = {
            'body_text': 1,
            'byline': 1,
        }
        self.assertEqual(projection, expected_projection)
开发者ID:dhazell,项目名称:superdesk,代码行数:16,代码来源:items_service_test.py

示例2: test_sets_fields_filter_on_request_object

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import projection [as 别名]
    def test_sets_fields_filter_on_request_object(self, fake_set_fields_filter):
        fake_request = MagicMock()
        fake_request.args = MultiDict()
        fake_request.projection = None
        lookup = {}

        instance = self._make_one()
        instance.find_one(fake_request, **lookup)

        self.assertTrue(fake_set_fields_filter.called)
        args, kwargs = fake_set_fields_filter.call_args

        self.assertGreater(len(args), 0)
        self.assertIs(args[0], fake_request)
开发者ID:dhazell,项目名称:superdesk,代码行数:16,代码来源:items_service_test.py

示例3: test_filters_out_blacklisted_fields_if_requested

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import projection [as 别名]
    def test_filters_out_blacklisted_fields_if_requested(self):
        request = MagicMock()
        request.args = MultiDict([('exclude_fields', 'language,version')])
        request.projection = None

        instance = self._make_one()
        instance._set_fields_filter(request)

        projection = json.loads(request.projection) if request.projection else {}
        expected_projection = {
            'language': 0,
            'version': 0,
        }
        self.assertEqual(projection, expected_projection)
开发者ID:dhazell,项目名称:superdesk,代码行数:16,代码来源:items_service_test.py

示例4: test_sets_fields_filter_on_request_object

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import projection [as 别名]
    def test_sets_fields_filter_on_request_object(self, fake_set_fields_filter):
        fake_request = MagicMock()
        fake_request.args = MultiDict()
        fake_request.projection = {}
        lookup = {}

        instance = self._make_one()
        instance.get(fake_request, lookup)

        self.assertTrue(fake_set_fields_filter.called)
        args, _ = fake_set_fields_filter.call_args

        self.assertGreater(len(args), 0)
        self.assertEqual(args[0].projection, {})
开发者ID:hlmnrmr,项目名称:superdesk-core,代码行数:16,代码来源:items_service_test.py

示例5: test_raises_error_if_requesting_to_exclude_required_field

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import projection [as 别名]
    def test_raises_error_if_requesting_to_exclude_required_field(self):
        request = MagicMock()
        request.args = MultiDict([('exclude_fields', 'uri')])
        request.projection = None

        from publicapi.errors import BadParameterValueError
        instance = self._make_one()

        with self.assertRaises(BadParameterValueError) as context:
            instance._set_fields_filter(request)

        ex = context.exception
        self.assertEqual(
            ex.payload,
            'Cannot exclude a content field required by the NINJS format '
            '(uri).'
        )
开发者ID:dhazell,项目名称:superdesk,代码行数:19,代码来源:items_service_test.py

示例6: test_raises_error_if_blacklisting_unknown_content_field

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import projection [as 别名]
    def test_raises_error_if_blacklisting_unknown_content_field(self):
        request = MagicMock()
        request.args = MultiDict([('exclude_fields', 'field_x')])
        request.projection = None

        from publicapi.errors import BadParameterValueError
        from publicapi.items import ItemsResource

        instance = self._make_one()

        fake_schema = {'foo': 'schema_bar'}
        with mock.patch.object(ItemsResource, 'schema', new=fake_schema):
            with self.assertRaises(BadParameterValueError) as context:
                instance._set_fields_filter(request)

            ex = context.exception
            self.assertEqual(
                ex.payload, 'Unknown content field to exclude (field_x).')
开发者ID:dhazell,项目名称:superdesk,代码行数:20,代码来源:items_service_test.py

示例7: test_raises_error_if_field_whitelist_and_blacklist_both_given

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import projection [as 别名]
    def test_raises_error_if_field_whitelist_and_blacklist_both_given(self):
        request = MagicMock()
        request.args = MultiDict([
            ('include_fields', 'language'),
            ('exclude_fields', 'body_text'),
        ])
        request.projection = None

        from publicapi.errors import UnexpectedParameterError
        instance = self._make_one()

        with self.assertRaises(UnexpectedParameterError) as context:
            instance._set_fields_filter(request)

        ex = context.exception
        self.assertEqual(
            ex.payload,
            'Cannot both include and exclude content fields at the same time.'
        )
开发者ID:dhazell,项目名称:superdesk,代码行数:21,代码来源:items_service_test.py


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