本文整理汇总了Python中mock.MagicMock.POST方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.POST方法的具体用法?Python MagicMock.POST怎么用?Python MagicMock.POST使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.POST方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unit_register_with_POST
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_unit_register_with_POST(self):
"""
We need to mock several things to make this unittest.
1. request
2. register_form() : For this, make seperate test.
- request has **method** attribute that specifies the method of the form.
3. Need to mock RegisterForm because we are not testing the register function.
- RegisterForm instance should have is_valid() method that returns boolean.
4. We need to mock HttpResponseRedirect.
"""
with patch('user_auth.views.RegisterForm') as form:
with patch('user_auth.views.HttpResponseRedirect') as redir:
request = MagicMock()
request.method = "POST" ## this will pass if request.POST == "POST" part.
request.POST = "some_input"
form.return_value = Mock()
form.return_value.is_valid = Mock(return_value=True)
# mock register_form
form.return_value.register_form = Mock(return_value=None)
register(request)
# make function call
form.assert_called_with("some_input")
# redir.assert_called_with('/')
self.assertTrue(form.return_value.register_form.called)
示例2: test_provider_redirects_on_success_preauth_payment
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [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: test_unit_login_user_with_post
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_unit_login_user_with_post(self):
"""
This function tests **login_user()** with post data.
We need to mock
1. request
2. LogInForm
- is_valid
- cleaned_data
3. authenticate
- is_active
4. render_to_response
"""
with patch('user_auth.views.LogInForm') as form:
request = MagicMock()
request.method = "POST"
request.POST = "some data"
form.return_value = Mock()
form.return_value.is_valid = Mock(return_value=True)
form.return_value.login_process = Mock()
with patch('user_auth.views.render_to_response') as render:
login_user(request)
form.return_value.login_process.assert_called_with(request)
form.assert_called_with("some data")
self.assertTrue(render.called)
示例4: test_unit_register_with_invalidPOST
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_unit_register_with_invalidPOST(self):
"""
This function tests the **register()** function with invalid post data.
we should mock
1. request
2. RegisterForm
- is_valid()
3. args
"""
with patch('user_auth.views.RegisterForm') as reg:
request = MagicMock()
request.method = "POST"
request.POST = "some input" # make input to RegisterForm
reg.return_value = Mock()
reg.return_value.is_valid = Mock(return_value=False) # make it pass the if part.
reg.return_value.register_form = Mock(return_value=None)
with patch('user_auth.views.render_to_response') as render:
render.return_value = "some value"
register(request)
# asserts
reg.assert_called_with("some input")
self.assertTrue(not reg.return_value.register_form.called)
self.assertTrue(render.called)
示例5: test_provider_invalid_request
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_provider_invalid_request(self):
request = MagicMock()
request.POST = {'jwt': 'wrong jwt data'}
provider = GoogleWalletProvider(payment=None, seller_id=SELLER_ID,
seller_secret=SELLER_SECRET)
token = provider.get_token_from_request(request)
self.assertFalse(token)
示例6: test_provider_request_payment_token
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_provider_request_payment_token(self):
request = MagicMock()
request.POST = {'jwt': jwt.encode(JWT_DATA, SELLER_SECRET)}
provider = GoogleWalletProvider(payment=None, seller_id=SELLER_ID,
seller_secret=SELLER_SECRET)
token = provider.get_token_from_request(request)
self.assertEqual(token, PAYMENT_TOKEN)
示例7: test_process_data
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_process_data(self):
"""DotpayProvider.process_data() returns a correct HTTP response"""
request = MagicMock()
request.POST = get_post_with_md5(PROCESS_POST)
provider = DotpayProvider(self.payment, seller_id='123', pin=PIN)
response = provider.process_data(request)
self.assertEqual(type(response), HttpResponse)
示例8: test_address_save_with_address_in_checkout
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_address_save_with_address_in_checkout(self):
request = MagicMock()
request.user.is_authenticated.return_value = False
request.POST = dict(NEW_ADDRESS, email='[email protected]')
storage = {'address': {}}
step = BillingAddressStep(request, storage)
self.assertTrue(step.forms_are_valid(), "Forms don't validate.")
示例9: test_incorrect_process_data
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_incorrect_process_data(self):
"""DotpayProvider.process_data() checks POST signature"""
request = MagicMock()
request.POST = PROCESS_POST
provider = DotpayProvider(self.payment, seller_id='123', pin=PIN)
response = provider.process_data(request)
self.assertEqual(type(response), HttpResponseForbidden)
示例10: test_incorrect_data_process_data
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_incorrect_data_process_data(self):
"""
CoinbaseProvider.process_data() checks request body
"""
request = MagicMock()
request.POST = {"id": "1234"}
response = self.provider.process_data(self.payment, request)
self.assertEqual(type(response), HttpResponseForbidden)
示例11: test_given_request_then_pass_to_correct_method
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_given_request_then_pass_to_correct_method(self):
request = MagicMock()
request.POST = "Post"
request.type_ = "Post"
request.endpoint = ["TestBlock", "device", "get_things"]
self.block.handle_request(request)
self.method.handle_request.assert_called_once_with(request)
示例12: test_address_save_without_address
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_address_save_without_address(self):
request = MagicMock()
request.user.is_authenticated.return_value = False
request.POST = dict(NEW_ADDRESS, email='[email protected]')
storage = {}
step = BillingAddressStep(request, storage)
self.assertEquals(step.process(), None)
self.assertEqual(type(storage['address']), dict)
self.assertEqual(storage['address']['name'], 'Test')
示例13: mock_request
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def mock_request(self, authed, path='/'):
mock_request = MagicMock()
mock_request.method = 'GET'
mock_request.user.is_authenticated.return_value = authed
mock_request.POST = {}
mock_request.META = {}
mock_request.session = {}
mock_request.build_absolute_uri.return_value = path
mock_request.get_full_path.return_value = path
return mock_request
示例14: _get_mock_request
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def _get_mock_request(self, twofactor_required=False, devices=None):
devices = devices or []
mock_request = MagicMock()
mock_request.user.is_authenticated.return_value = True
mock_request.user.preferredemail.email = '[email protected]'
mock_request.user.twofactor_required = twofactor_required
mock_request.method = 'GET'
mock_request.POST = {}
mock_request.META = {}
mock_request.user.devices.all.return_value = devices
return mock_request
示例15: test_new_method
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import POST [as 别名]
def test_new_method(self):
'''
Test the BaseAddressStep managment form when method is set to 'new'
and user isn't authenticated.
'''
request = MagicMock()
request.user.is_authenticated.return_value = False
request.POST = NEW_ADDRESS.copy()
step = BaseAddressStep(request, {}, Address(**NEW_ADDRESS))
self.assertTrue(step.forms_are_valid(), "Forms don't validate.")
self.assertEqual(step.address.name, 'Test')