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


Python MagicMock.args方法代码示例

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


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

示例1: test_aggregations

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import args [as 别名]
    def test_aggregations(self):
        fake_request = MagicMock()
        fake_request.args = MultiDict([('aggregations', 1)])
        lookup = {}
        fake_response = MagicMock()
        fake_response.count.return_value = 1
        fake_super_get.return_value = fake_response

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

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

        self.assertGreater(len(args), 0)
        self.assertEqual(args[0].args['aggregations'], 1)

        fake_request = MagicMock()
        fake_request.args = MultiDict([('aggregations', 0)])
        lookup = {}

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

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

        self.assertGreater(len(args), 0)
        self.assertEqual(args[0].args['aggregations'], 0)
开发者ID:jerome-poisson,项目名称:superdesk-core,代码行数:31,代码来源:search_service_test.py

示例2: test_correctly_invokes_parameter_validation

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

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

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

        self.assertGreater(len(args), 0)
        self.assertEqual(args[0], fake_request)
        self.assertEqual(kwargs.get('allow_filtering'), False)

        expected_whitelist = sorted(['exclude_fields', 'include_fields'])

        whitelist_arg = kwargs.get('whitelist')
        if whitelist_arg is not None:
            # NOTE: the whitelist argument is converted to a list, because any
            # iterable type is valid, not just lists
            self.assertEqual(sorted(list(whitelist_arg)), expected_whitelist)
        else:
            # whitelist can also be passed as a positional argument
            self.assertGreater(len(args), 1)
            self.assertEqual(sorted(list(args[1])), expected_whitelist)
开发者ID:dhazell,项目名称:superdesk,代码行数:28,代码来源:items_service_test.py

示例3: test_does_not_raise_an_error_on_valid_parameters

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import args [as 别名]
    def test_does_not_raise_an_error_on_valid_parameters(self):
        request = MagicMock()
        request.args = MultiDict([('sort_by', 'language')])
        instance = self._make_one()

        try:
            instance._check_for_unknown_params(request, ('foo', 'sort_by', 'bar'))
        except Exception as ex:
            self.fail("Exception unexpectedly raised ({})".format(ex))
开发者ID:dhazell,项目名称:superdesk,代码行数:11,代码来源:items_service_test.py

示例4: test_sets_query_filter_on_request_object_if_present

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import args [as 别名]
    def test_sets_query_filter_on_request_object_if_present(self):
        request = MagicMock()
        request.args = dict(q='{"language": "de"}')
        lookup = {}

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

        self.assertTrue(fake_super_get.called)
        args, kwargs = fake_super_get.call_args
        self.assertGreater(len(args), 0)
        self.assertEqual(args[0].where, '{"language": "de"}')
开发者ID:wilane,项目名称:superdesk,代码行数:14,代码来源:items_service_test.py

示例5: test_raises_correct_error_on_unexpected_parameters

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import args [as 别名]
    def test_raises_correct_error_on_unexpected_parameters(self):
        request = MagicMock()
        request.args = MultiDict([('param_x', 'something')])

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

        with self.assertRaises(UnexpectedParameterError) as context:
            instance._check_for_unknown_params(request, ('foo', 'bar'))

        ex = context.exception
        self.assertEqual(ex.payload, 'Unexpected parameter (param_x)')
开发者ID:dhazell,项目名称:superdesk,代码行数:14,代码来源:items_service_test.py

示例6: test_allows_start_and_end_dates_to_be_equal

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import args [as 别名]
    def test_allows_start_and_end_dates_to_be_equal(self):
        request = MagicMock()
        request.args = MultiDict([
            ('start_date', '2010-01-28'),
            ('end_date', '2010-01-28')
        ])
        lookup = {}
        instance = self._make_one()

        try:
            instance.get(request, lookup)
        except Exception as ex:
            self.fail("Exception unexpectedly raised ({})".format(ex))
开发者ID:dhazell,项目名称:superdesk,代码行数:15,代码来源:items_service_test.py

示例7: test_invokes_superclass_method_with_given_arguments

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

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

        self.assertTrue(fake_super_get.called)
        args, kwargs = fake_super_get.call_args
        self.assertEqual(len(args), 2)
        self.assertIs(args[0], request)
        self.assertIs(args[1], lookup)
开发者ID:dhazell,项目名称:superdesk,代码行数:15,代码来源:items_service_test.py

示例8: test_raises_correct_error_on_duplicate_parameters

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import args [as 别名]
    def test_raises_correct_error_on_duplicate_parameters(self):
        request = MagicMock()
        request.args = MultiDict([('foo', 'value 1'), ('foo', 'value 2')])

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

        with self.assertRaises(UnexpectedParameterError) as context:
            instance._check_for_unknown_params(request, whitelist=('foo',))

        ex = context.exception
        self.assertEqual(
            ex.payload, "Multiple values received for parameter (foo)")
开发者ID:dhazell,项目名称:superdesk,代码行数:15,代码来源:items_service_test.py

示例9: test_raises_correct_error_on_unexpected_parameters

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import args [as 别名]
    def test_raises_correct_error_on_unexpected_parameters(self):
        request = MagicMock()
        request.args = dict(foo='bar')
        lookup = {}

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

        with self.assertRaises(UnexpectedParameterError) as context:
            instance.get(request, lookup)

        ex = context.exception
        self.assertEqual(ex.desc, 'Unexpected parameter (foo)')
开发者ID:wilane,项目名称:superdesk,代码行数:15,代码来源:items_service_test.py

示例10: test_sets_fields_filter_on_request_object

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

示例11: test_filters_out_all_but_whitelisted_fields_if_requested

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

示例12: test_sets_query_filter_on_request_object_if_present

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import args [as 别名]
    def test_sets_query_filter_on_request_object_if_present(self):
        request = MagicMock()
        request.args = MultiDict([('q', '{"language": "de"}')])
        lookup = {}

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

        self.assertTrue(fake_super_get.called)
        args, kwargs = fake_super_get.call_args
        self.assertGreater(len(args), 0)

        query_filter = json.loads(args[0].where)
        self.assertEqual(query_filter.get('language'), 'de')
开发者ID:dhazell,项目名称:superdesk,代码行数:16,代码来源:items_service_test.py

示例13: test_sets_fields_filter_on_request_object

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

示例14: test_filters_out_blacklisted_fields_if_requested

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

示例15: test_raises_descriptive_error_on_filtering_disabled

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import args [as 别名]
    def test_raises_descriptive_error_on_filtering_disabled(self):
        request = MagicMock()
        request.args = MultiDict([('q', '{"language": "en"}')])

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

        with self.assertRaises(UnexpectedParameterError) as context:
            instance._check_for_unknown_params(
                request, whitelist=(), allow_filtering=False)

        ex = context.exception
        self.assertEqual(
            ex.payload,
            'Unexpected parameter (q)'
        )
开发者ID:superdesk,项目名称:superdesk-core,代码行数:18,代码来源:items_service_test.py


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