本文整理汇总了Python中unittest.mock.Mock.POST方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.POST方法的具体用法?Python Mock.POST怎么用?Python Mock.POST使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.POST方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_receive_when_target_not_in_post_data
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
def test_receive_when_target_not_in_post_data(self):
request = Mock()
request.method = 'POST'
request.POST = {'source': self.source}
response = receive(request)
self.assertTrue(isinstance(response, HttpResponseBadRequest))
示例2: test_receive_when_target_does_not_resolve
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
def test_receive_when_target_does_not_resolve(self, mock_url_resolves):
request = Mock()
request.method = 'POST'
request.POST = {'source': self.source, 'target': self.target}
mock_url_resolves.return_value = False
response = receive(request)
mock_url_resolves.assert_called_once_with(self.target)
self.assertTrue(isinstance(response, HttpResponseBadRequest))
示例3: _get_request
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
def _get_request(self):
"""Gets mocked request."""
request = Mock()
request.POST = {
'code': 'code',
'state': 'state',
}
request.session = MagicMock()
request.session.__setitem__.return_value = None
request.session.save.return_value = None
return request
示例4: test_receive_when_general_exception_occurs
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
def test_receive_when_general_exception_occurs(self, mock_url_resolves, mock_fetch_and_validate_source):
request = Mock()
request.method = 'POST'
request.POST = {'source': self.source, 'target': self.target}
mock_url_resolves.return_value = True
mock_fetch_and_validate_source.side_effect = Exception
response = receive(request)
mock_fetch_and_validate_source.assert_called_once_with(self.source, self.target)
mock_url_resolves.assert_called_once_with(self.target)
self.assertTrue(isinstance(response, HttpResponseServerError))
示例5: test_has_permission_not_member_of_company
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
def test_has_permission_not_member_of_company(self):
permission = permissions.IsMemberOfBrewingCompany()
user = User.objects.create(username="user")
group = Group.objects.create(name="group")
brewing_company = models.BrewingCompany.objects.create(group=group)
request = Mock()
request.user = user
request.method = "POST"
request.POST = {
"company": brewing_company.pk,
}
view = None
self.assertFalse(permission.has_permission(request, view))
示例6: test_receive_when_source_does_not_contain_target
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
def test_receive_when_source_does_not_contain_target(self, mock_url_resolves, mock_fetch_and_validate_source, mock_invalidate):
request = Mock()
request.method = 'POST'
request.POST = {'source': self.source, 'target': self.target}
mock_url_resolves.return_value = True
mock_fetch_and_validate_source.side_effect = TargetNotFoundError
response = receive(request)
mock_fetch_and_validate_source.assert_called_once_with(self.source, self.target)
mock_url_resolves.assert_called_once_with(self.target)
self.assertEqual(1, mock_invalidate.call_count)
self.assertTrue(isinstance(response, HttpResponseBadRequest))
示例7: test_receive_happy_path
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
def test_receive_happy_path(self, mock_url_resolves, mock_fetch_and_validate_source, mock_update):
request = Mock()
request.method = 'POST'
request.POST = {'source': self.source, 'target': self.target}
mock_url_resolves.return_value = True
mock_fetch_and_validate_source.return_value = 'foo'
response = receive(request)
mock_fetch_and_validate_source.assert_called_once_with(self.source, self.target)
mock_update.assert_called_once_with(self.source, self.target, mock_fetch_and_validate_source.return_value)
mock_url_resolves.assert_called_once_with(self.target)
self.assertTrue(isinstance(response, HttpResponse))
示例8: _create_request
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
def _create_request(self):
"""Gets mocked request."""
request = Mock()
request.POST = {
'code': 'code',
'state': 'state',
}
request.user = User(email='[email protected]')
request.user.save()
request.session = MagicMock()
request.session.__setitem__.return_value = None
request.session.__getitem__.side_effect = _fake_session
request.session.get.side_effect = _fake_session
request.session.save.return_value = None
return request
示例9: test_has_permission_member_of_company
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import POST [as 别名]
def test_has_permission_member_of_company(self):
permission = permissions.OwnsRecipe()
user = User.objects.create(username="user")
group = Group.objects.create(name="group")
group.user_set.add(user)
brewing_company = models.BrewingCompany.objects.create(group=group)
recipe = models.Recipe.objects.create(company=brewing_company)
request = Mock()
request.user = user
request.method = "POST"
request.POST = {
"recipe": recipe.pk,
}
view = None
self.assertTrue(permission.has_permission(request, view))