本文整理汇总了Python中mock.MagicMock.GET方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.GET方法的具体用法?Python MagicMock.GET怎么用?Python MagicMock.GET使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.GET方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_provider_redirects_on_success_preauth_payment
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_provider_redirects_on_success_preauth_payment(
self, mocked_redirect, mocked_post):
data = MagicMock()
data.return_value = {
'token_type': 'test_token_type',
'access_token': 'test_access_token',
'payer': {'payer_info': 'test123'},
'transactions': [
{'related_resources': [{
'sale': {'links': ''},
'authorization': {'links': ''}}]}
]}
post = MagicMock()
post.json = data
post.status_code = 200
mocked_post.return_value = post
request = MagicMock()
request.GET = {'token': 'test', 'PayerID': '1234'}
provider = PaypalProvider(
secret=SECRET, client_id=CLIENT_ID, capture=False)
provider.process_data(self.payment, request)
self.assertEqual(self.payment.status, 'preauth')
self.assertEqual(self.payment.captured_amount, Decimal('0'))
示例2: test_provider_redirects_on_success_preauth_payment
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_provider_redirects_on_success_preauth_payment(
self, mocked_request, mocked_redirect):
provider = CyberSourceProvider(
merchant_id=MERCHANT_ID, password=PASSWORD, org_id=ORG_ID,
capture=False)
transaction_id = 1234
xid = 'abc'
self.payment.attrs.xid = xid
response = MagicMock()
response.requestID = transaction_id
response.reasonCode = ACCEPTED
mocked_request.return_value = response
request = MagicMock()
request.POST = {'MD': xid}
request.GET = {'token': signing.dumps({
'expiration': {'year': 2020, 'month': 9},
'name': 'John Doe',
'number': '371449635398431',
'cvv2': '123'
})}
provider.process_data(self.payment, request)
self.assertEqual(self.payment.status, 'preauth')
self.assertEqual(self.payment.captured_amount, 0)
self.assertEqual(self.payment.transaction_id, transaction_id)
示例3: request
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def request(self, lti_launch={"custom_canvas_api_domain": TEST_DOMAIN},
get_params={}):
request = MagicMock()
session = {"oauth_return_uri": self.TEST_DOMAIN}
if lti_launch:
session["LTI_LAUNCH"] = lti_launch
request.session = session
request.GET = get_params
request.user.oauthtoken.updated_on = TEST_TIME
return request
示例4: test_provider_redirects_on_failure
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_provider_redirects_on_failure(
self, mocked_redirect, mocked_post, mocked_parser):
transaction_id = '1234'
request = MagicMock()
request.GET = {'trans': transaction_id}
mocked_parser.return_value = {}
self.provider.process_data(self.payment, request)
self.assertEqual(self.payment.status, 'rejected')
self.assertEqual(self.payment.captured_amount, 0)
self.assertEqual(self.payment.transaction_id, transaction_id)
示例5: test_phone_number_that_has_the_COUNTRY_PHONE_CODE_finds_the_investigator_unit
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_phone_number_that_has_the_COUNTRY_PHONE_CODE_finds_the_investigator_unit(self, mock_investigator_not_registered):
mobile_number = '123'+COUNTRY_PHONE_CODE+'456'
Interviewer.objects.create(name='Inv1', ea=self.ea, mobile_number=mobile_number, backend=self.backend)
self.ussd_params['msisdn']= COUNTRY_PHONE_CODE + mobile_number
request = MagicMock()
request.GET = self.ussd_params
ussd(request)
self.assertFalse(mock_investigator_not_registered.called)
示例6: mock_request
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def mock_request(self, request_group):
"""Build a mock request (for self.s_admin).
Args:
request_group: The group that the user is requesting access to.
"""
request = MagicMock()
request.resolver_match.kwargs = {}
request.GET = {}
request.GET['group'] = request_group
return request
示例7: _build_mock_request
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def _build_mock_request(self, user=None, get=None, post=None):
request = MagicMock()
if user:
request.user = user
request.user.is_authenticated = MagicMock(return_value=True)
else:
request.user = AnonymousUser()
request.GET = {}
request.POST = {}
request.resolver_match.kwargs = {}
if get is not None:
request.GET.update(get)
if post is not None:
request.POST.update(post)
return request
示例8: test_provider_redirects_on_success
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_provider_redirects_on_success(
self, mocked_redirect, mocked_post, mocked_parser):
transaction_id = '1234'
request = MagicMock()
request.GET = {'trans': transaction_id}
mocked_parser.return_value = {
'transactions': {
'transaction_details': {
'status': 'ok',
'sender': {
'holder': 'John Doe',
'country_code': 'EN'}}}}
self.provider.process_data(self.payment, request)
self.assertEqual(self.payment.status, 'confirmed')
self.assertEqual(self.payment.captured_amount, self.payment.total)
self.assertEqual(self.payment.transaction_id, transaction_id)
示例9: test_oauth
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_oauth(self):
# Test GET to ensure a provider name is returned for dynamically naming oauth login.
oauth_name = "provider"
client_id = "name"
redirect_uri = "http://test.dev/callback"
response_type = "code"
scope = "profile"
authorization_url = "http://remote.dev/authorize"
referer = "/status/12345"
with self.settings(OAUTH_NAME=oauth_name):
response = self.client.get(reverse('oauth'),{'query':'name'})
return_name = response.json().get('name')
self.assertEqual(return_name, oauth_name)
self.assertEqual(response.status_code, 200)
# Test post to ensure that a valid redirect is returned.
with self.settings(OAUTH_CLIENT_ID=client_id,
OAUTH_REDIRECT_URI=redirect_uri,
OAUTH_RESPONSE_TYPE=response_type,
OAUTH_SCOPE=scope,
OAUTH_NAME=oauth_name):
response = self.client.post(reverse('oauth'))
params = urllib.parse.urlencode((
('client_id', client_id),
('redirect_uri', redirect_uri),
('response_type', response_type),
('scope', scope)
))
self.assertRedirects(response, '{url}?{params}'.format(url=authorization_url.rstrip('/'),
params=params),
fetch_redirect_response=False)
mock_request = MagicMock()
mock_request.META = {'HTTP_REFERER': referer}
mock_request.GET = {'query': None}
response = oauth(mock_request)
params = urllib.parse.urlencode((
('client_id', client_id),
('redirect_uri', redirect_uri),
('response_type', response_type),
('scope', scope),
('state', base64.b64encode(referer.encode()))
))
self.assertRedirects(response, '{url}?{params}'.format(url=authorization_url.rstrip('/'),
params=params),
fetch_redirect_response=False)
示例10: test_jsonp_returns_with_callback
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_jsonp_returns_with_callback():
f = MagicMock()
f.__name__ = 'Wrapped View'
# Setup the mock request
request = MagicMock()
request.GET = dict(callback='init')
# Setup the mock response.
json = {"id": 1, "status": 200}
response = MagicMock(content=json, status_code=200)
f.return_value = response
decorated_f = jsonp(f)
result = decorated_f(request)
expected = 'init({0})'.format(json)
assert expected == result.content
示例11: _build_mock_request
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def _build_mock_request(self, user=None, get=None, post=None):
request = MagicMock()
if user:
request.user = user
if django.VERSION[:2] >= (1, 10):
# Django 1.10 made `User.is_authenticated` into a property for
# some reason.
request.user.is_authenticated.__get__ = MagicMock(return_value=True) # nopep8
else:
request.user.is_authenticated = MagicMock(return_value=True)
else:
request.user = AnonymousUser()
request.GET = {}
request.POST = {}
request.resolver_match.kwargs = {}
if get is not None:
request.GET.update(get)
if post is not None:
request.POST.update(post)
return request
示例12: test_jsonp_request_does_not_have_callback
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_jsonp_request_does_not_have_callback():
"""Test the outcome when the input request does not contain a
callback.
"""
f = MagicMock()
f.__name__ = 'Wrapped View'
request = MagicMock()
# No query strings are added.
request.GET = dict()
json = {"id": 1, "status": 200}
response = MagicMock(content=json, status_code=200)
f.return_value = response
decorated_f = jsonp(f)
result = decorated_f(request)
# Here we assert the the content was not altered
# since we did not provide a callback.
assert json == result.content
示例13: test_provider_redirects_on_success_captured_payment
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_provider_redirects_on_success_captured_payment(
self, mocked_redirect, mocked_post):
data = MagicMock()
data.return_value = {
'token_type': 'test_token_type',
'access_token': 'test_access_token',
'payer': {'payer_info': 'test123'},
'transactions': [
{'related_resources': [{
'sale': {'links': ''},
'authorization': {'links': ''}}]}
]}
post = MagicMock()
post.json = data
post.status_code = 200
mocked_post.return_value = post
request = MagicMock()
request.GET = {'token': 'test', 'PayerID': '1234'}
self.provider.process_data(self.payment, request)
self.assertEqual(self.payment.status, 'confirmed')
self.assertEqual(self.payment.captured_amount, self.payment.total)
示例14: test_provider_redirects_on_failure
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_provider_redirects_on_failure(
self, mocked_request, mocked_redirect):
transaction_id = 1234
xid = 'abc'
self.payment.attrs.xid = xid
response = MagicMock()
response.requestID = transaction_id
response.reasonCode = 'test code'
mocked_request.return_value = response
request = MagicMock()
request.POST = {'MD': xid}
request.GET = {'token': signing.dumps({
'expiration': {'year': 2020, 'month': 9},
'name': 'John Doe',
'number': '371449635398431',
'cvv2': '123'
})}
self.provider.process_data(self.payment, request)
self.assertEqual(self.payment.status, 'error')
self.assertEqual(self.payment.captured_amount, 0)
self.assertEqual(self.payment.transaction_id, transaction_id)
示例15: test_provider_request_without_payerid_redirects_on_failure
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import GET [as 别名]
def test_provider_request_without_payerid_redirects_on_failure(
self, mocked_redirect):
request = MagicMock()
request.GET = {'token': 'test', 'PayerID': None}
self.provider.process_data(self.payment, request)
self.assertEqual(self.payment.status, 'rejected')