本文整理汇总了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])
示例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"])
示例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'])
示例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'])
示例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])
示例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'])
示例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'])
示例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])
示例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), [])
示例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])
示例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'])
示例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')
示例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')
示例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)
示例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)