本文整理汇总了Python中mock.Mock.GET方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.GET方法的具体用法?Python Mock.GET怎么用?Python Mock.GET使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.GET方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_channel_in_get
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_channel_in_get(self):
for ch in CHANNELS:
request = Mock()
request.path_info = '/'
request.GET = dict(channel=ch)
p = urlresolvers.Prefixer(request)
eq_(p.get_channel(), ch)
# Invalid channel
request = Mock()
request.path_info = '/'
request.GET = dict(channel='bogus')
p = urlresolvers.Prefixer(request)
eq_(p.get_channel(), settings.DEFAULT_CHANNEL)
示例2: _test_mobile_persona_ctx
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def _test_mobile_persona_ctx(self):
request = Mock()
request.APP = amo.FIREFOX
request.GET = {}
request.user.is_authenticated.return_value = False
request.user.mobile_addons = []
return {'APP': amo.FIREFOX, 'LANG': 'en-US', 'request': request}
示例3: test_pagesize
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_pagesize(self):
"""``pagenumber`` gets the pagenumber from the request."""
from moztrap.view.lists.templatetags.pagination import pagesize
request = Mock()
request.GET = {"pagenumber": 2, "pagesize": 10}
self.assertEqual(pagesize(request), 10)
示例4: test_set_default_flavour
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_set_default_flavour(self):
request = Mock()
request.GET = {}
middleware = SetFlavourMiddleware()
middleware.process_request(request)
# default flavour is set
self.assertEqual(get_flavour(), "full")
示例5: test_get_results
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_get_results(is_valid):
is_valid.return_value = False
request = Mock()
request.GET = {}
request.default_prod = FIREFOX
r = views._get_results(request)
eq_(r[2], request.default_prod)
示例6: test_get_limit_invalid_limit_existing_error
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_get_limit_invalid_limit_existing_error(self, mock_request):
mock_request = Mock()
mock_request.GET = {'limit': 'I like Pi'}
original_error = {
'debug': "This is an existing error",
'status': True,
'level': 'Important',
'text': 'This error already exists',
'name': "I've errored!"
}
expected_error = {
'debug': "ValueError: invalid literal for int() "
"with base 10: 'I like Pi'",
'status': True,
'level': 'Warning',
'text': 'Invalid limit. Returning all results.',
'name': 'Bad Limit'
}
expected_result = [None, expected_error]
actual_result = get_limit(mock_request, original_error)
self.assertEqual(expected_result, actual_result)
示例7: prepare_request_mock
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def prepare_request_mock(self, data, referer='http://localhost/user_with_workspaces/Public Workspace', user=None, extra_headers={}, GET=''):
request = Mock()
request.method = 'POST'
request.get_host.return_value = 'localhost'
GET_PARAMETERS = parse_qsl(GET)
request.GET = MagicMock()
request.GET.__len__.side_effect = lambda: len(GET_PARAMETERS)
request.GET.__getitem__.side_effect = lambda key: GET_PARAMETERS[key]
request.GET.urlencode.side_effect = lambda: GET
request.COOKIES = {
settings.SESSION_COOKIE_NAME: 'test',
}
request.META = {
'HTTP_ACCEPT': 'application/json',
'SERVER_PROTOCOL': 'http',
'REMOTE_ADDR': '127.0.0.1',
'content_type': 'application/json',
'content_length': len(data),
'HTTP_HOST': 'localhost',
'HTTP_REFERER': referer,
'HTTP_X_FI_WARE_OAUTH_TOKEN': 'true',
}
request.META.update(extra_headers)
request.read.return_value = data
if user is None:
request.user = self.admin_mock
else:
request.user = user
return request
示例8: test_get_limit_valid_limit
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_get_limit_valid_limit(self, mock_request):
mock_request = Mock()
mock_request.GET = {'limit': '80'}
expected_result = [80, self.base_error]
actual_result = get_limit(mock_request, self.base_error)
self.assertEqual(expected_result, actual_result)
示例9: setUp
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def setUp(self):
request = Mock()
request.method = 'GET'
request.GET = {'msgid': 'the-msgid'}
get_all_translations = Mock(return_value={"dummy": "json"})
with patch('livetranslation.views.get_all_translations',
get_all_translations):
self.response = get_translations(request)
示例10: cls
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def cls(self, full_path, GET):
"""Construct mock request; instantiate and return Sort object."""
request = Mock()
request.GET = GET
request.get_full_path.return_value = full_path
from cc.view.lists.sort import Sort
return Sort(request)
示例11: test_set_flavour_through_get_parameter
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_set_flavour_through_get_parameter(self, set_flavour):
request = Mock()
request.META = MagicMock()
request.GET = {'flavour': 'mobile'}
middleware = SetFlavourMiddleware()
middleware.process_request(request)
self.assertEqual(set_flavour.call_args,
(('mobile', request), {'permanent': True}))
示例12: test_max_request
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_max_request(self):
SilkyConfig().SILKY_MAX_REQUEST_BODY_SIZE = 10 # 10kb
mock_request = Mock()
mock_request.META = {'CONTENT_TYPE': 'text/plain'}
mock_request.GET = {}
mock_request.body = 'a'.encode('ascii') * 1024 * 100 # 100kb
request_model = RequestModelFactory(mock_request).construct_request_model()
self.assertFalse(request_model.raw_body)
示例13: test_should_import_data_senders
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_should_import_data_senders(self):
file_name = "reporters.csv"
request = Mock()
request.GET = {'qqfile' : file_name}
request.raw_post_data = self.csv_data
error_message, failure_imports, success, success_message = import_data(request=request,manager = self.dbm)
self.assertTrue(success)
self.assertEqual(4,get_entity_count_for_type(self.dbm,entity_type="reporter"))
示例14: test_no_long_url
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_no_long_url(self):
url = '1234567890' * 19 # 190-character URL
mock_request = Mock()
mock_request.META = {'CONTENT_TYPE': 'text/plain'}
mock_request.GET = {}
mock_request.path = url
mock_request.method = 'get'
request_model = RequestModelFactory(mock_request).construct_request_model()
self.assertEqual(request_model.path, url)
示例15: test_max_request
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import GET [as 别名]
def test_max_request(self):
SilkyConfig().SILKY_MAX_REQUEST_BODY_SIZE = 10 # 10kb
mock_request = Mock()
mock_request.META = {"CONTENT_TYPE": "text/plain"}
mock_request.GET = {}
mock_request.body = "a".encode("ascii") * 1024 * 100 # 100kb
mock_request.path = reverse("silk:requests")
request_model = RequestModelFactory(mock_request).construct_request_model()
self.assertFalse(request_model.raw_body)