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


Python MagicMock.query_params方法代码示例

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


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

示例1: test_parse_int_list_accepted_none

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_int_list_accepted_none(self):
        """Tests parsing a list of int parameters where none of the values are acceptable."""
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['1', '2'])

        self.assertRaises(BadParameter, rest_util.parse_int_list, request, 'test', accepted_values=[3])
开发者ID:ngageoint,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例2: test_filter_terms_regexp

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_filter_terms_regexp(self):
        """Test search object filtering using terms and regexp.

        Because their values are dicts, these take a different code path than
        "standard" match queries.

        """

        view = ElasticListAPIView()
        view.Meta.model = MagicMock()
        view.Meta.model.field_has_raw.return_value = False

        EXPECTED = [
            {"regexp": {"this.is.a.nested.field": ".+12345666666666"}},
            {"terms": {"_type": ["audit.http.request", "audit.http.response", "identity.*"]}},
        ]

        elasticfilter = ElasticFilter()
        request = MagicMock()

        # Set up the query terms for the test.
        request.query_params = QueryDict("", mutable=True)
        request.query_params.update(
            {
                view.pagination_class.page_query_param: "ignored",
                "terms": {"_type": ["audit.http.request", "audit.http.response", "identity.*"]},
                "regexp": {"this.is.a.nested.field": ".+12345666666666"},
            }
        )

        result = elasticfilter.filter_queryset(request, Search(), view).to_dict()

        for item in EXPECTED:
            self.assertTrue(item in result["query"]["bool"]["must"])
开发者ID:leftees,项目名称:goldstone-server,代码行数:36,代码来源:tests.py

示例3: test_parse_string_list

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_string_list(self):
        """Tests parsing a required list of string parameters that is provided via GET."""
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1', 'value2'])

        self.assertListEqual(rest_util.parse_string_list(request, 'test'), ['value1', 'value2'])
开发者ID:ngageoint,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例4: test_parse_string_list_accepted_partial

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_string_list_accepted_partial(self):
        """Tests parsing a list of string parameters where only some values are acceptable."""
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1', 'value2'])

        self.assertRaises(BadParameter, rest_util.parse_string_list, request, 'test', accepted_values=['value1'])
开发者ID:ngageoint,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例5: test_parse_int_list

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_int_list(self):
        '''Tests parsing a required list of int parameters that is provided via GET.'''
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['1', '2'])

        self.assertListEqual(rest_util.parse_int_list(request, 'test'), [1, 2])
开发者ID:AppliedIS,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例6: test_parse_string_list_accepted_none

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_string_list_accepted_none(self):
        '''Tests parsing a list of string parameters where none of the values are acceptable.'''
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1', 'value2'])

        self.assertRaises(BadParameter, rest_util.parse_string_list, request, 'test', accepted_values=['value'])
开发者ID:AppliedIS,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例7: test_filter_queryset

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_filter_queryset(self):
        """Test search object filtering."""

        view = ElasticListAPIView()
        view.Meta.model = MagicMock()
        view.Meta.model.field_has_raw.return_value = False

        elasticfilter = ElasticFilter()
        request = MagicMock()

        # Set up the query terms for the test.
        request.query_params = QueryDict('', mutable=True)

        request.query_params.update(
            {view.pagination_class.page_query_param: 'ignored',
             'name': 'value',
             'name__terms': '["value1","value2"]'}
        )

        result = \
            elasticfilter.filter_queryset(request, Search(), view).to_dict()

        EXPECTED = [{'terms': {u'name': ['value1', 'value2']}},
                    {'match': {u'name': 'value'}}]

        for item in EXPECTED:
            self.assertTrue(item in result['query']['bool']['must'])
开发者ID:bhuvan-rk,项目名称:goldstone-server,代码行数:29,代码来源:tests.py

示例8: test_parse_int_list_accepted_all

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_int_list_accepted_all(self):
        '''Tests parsing a list of int parameters where all values are acceptable.'''
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['1', '2'])

        self.assertListEqual(rest_util.parse_int_list(request, 'test', accepted_values=[1, 2]), [1, 2])
开发者ID:AppliedIS,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例9: test_parse_string_list_optional

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_string_list_optional(self):
        '''Tests parsing an optional list of string parameters that are missing.'''
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1'])

        self.assertListEqual(rest_util.parse_string_list(request, 'test2', required=False), [])
开发者ID:AppliedIS,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例10: test_parse_int_list_accepted_partial

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_int_list_accepted_partial(self):
        '''Tests parsing a list of int parameters where only some values are acceptable.'''
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['1', '2'])

        self.assertRaises(BadParameter, rest_util.parse_int_list, request, 'test', accepted_values=[1])
开发者ID:AppliedIS,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例11: test_parse_string_list_default

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_string_list_default(self):
        '''Tests parsing a required list of string parameters that are provided via default value.'''
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1'])

        self.assertEqual(rest_util.parse_string_list(request, 'test2', ['value2', 'value3']), ['value2', 'value3'])
开发者ID:AppliedIS,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例12: test_parse_string_list_missing

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
    def test_parse_string_list_missing(self):
        '''Tests parsing a required list of string parameters that are missing.'''
        request = MagicMock(Request)
        request.query_params = QueryDict('', mutable=True)
        request.query_params.setlist('test', ['value1', 'value2'])

        self.assertRaises(BadParameter, rest_util.parse_string_list, request, 'test2')
开发者ID:AppliedIS,项目名称:scale,代码行数:9,代码来源:test_rest.py

示例13: test_parse_float_invalid

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
 def test_parse_float_invalid(self):
     '''Tests parsing a required float parameter that is not a valid number.'''
     request = MagicMock(Request)
     request.query_params = QueryDict('', mutable=True)
     request.query_params.update({
         'test': 'abc',
     })
     self.assertRaises(BadParameter, rest_util.parse_float, request, 'test')
开发者ID:AppliedIS,项目名称:scale,代码行数:10,代码来源:test_rest.py

示例14: test_parse_float_zero

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
 def test_parse_float_zero(self):
     '''Tests parsing an optional float parameter zero instead of using the default value.'''
     request = MagicMock(Request)
     request.query_params = QueryDict('', mutable=True)
     request.query_params.update({
         'test': '0.0',
     })
     self.assertEqual(rest_util.parse_float(request, 'test', 10.1), 0.0)
开发者ID:AppliedIS,项目名称:scale,代码行数:10,代码来源:test_rest.py

示例15: test_parse_float_default

# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import query_params [as 别名]
 def test_parse_float_default(self):
     '''Tests parsing a required float parameter that is provided via default value.'''
     request = MagicMock(Request)
     request.query_params = QueryDict('', mutable=True)
     request.query_params.update({
         'test': '10.1',
     })
     self.assertEqual(rest_util.parse_float(request, 'test2', 20.1), 20.1)
开发者ID:AppliedIS,项目名称:scale,代码行数:10,代码来源:test_rest.py


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