本文整理汇总了Python中unittest.mock.Mock.method方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.method方法的具体用法?Python Mock.method怎么用?Python Mock.method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request_mock
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def request_mock():
request = Mock()
request.method = 'GET'
request.headers = {'Accept': 'appliaction/json'}
request.body = None
request.uri = '/'
return request
示例2: test_has_permission_fails_with_no_user
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def test_has_permission_fails_with_no_user(self):
permission = permissions.IsContinuousIntegrationToEdit()
request = Mock()
request.method = 'POST'
request.user = None
view = None
self.assertFalse(permission.has_permission(request, view))
示例3: test_has_permission_with_get
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def test_has_permission_with_get(self):
permission = permissions.IsContinuousIntegrationToEdit()
user = User.objects.create(username="user")
request = Mock()
request.user = user
request.method = 'GET'
view = None
self.assertTrue(permission.has_permission(request, view))
示例4: test_MethodsView_call
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def test_MethodsView_call(loop, MVw): # noqa
request = Mock(name='request')
request.method = 'GET'
resource = Mock(name='resource')
tail = ('ta', 'il')
resp = loop.run_until_complete(MVw(request, resource, tail)())
assert resp == 'data'
示例5: test_MethodsView_call__not_implemented
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def test_MethodsView_call__not_implemented(loop, MVw): # noqa
request = Mock(name='request')
request.method = 'POST'
resource = Mock(name='resource')
tail = ('ta', 'il')
with pytest.raises(NotImplementedError):
loop.run_until_complete(MVw(request, resource, tail)())
示例6: test_MethodsView_call__not_allowed
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def test_MethodsView_call__not_allowed(loop, MVw): # noqa
request = Mock(name='request')
request.method = 'DELETE'
resource = Mock(name='resource')
tail = ('ta', 'il')
with pytest.raises(HTTPMethodNotAllowed):
loop.run_until_complete(MVw(request, resource, tail)())
示例7: test_RESTView__response
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def test_RESTView__response(loop, RVw): # noqa
request = Mock(name='request')
request.method = 'POST'
resource = Mock(name='resource')
tail = ('ta', 'il')
resp = loop.run_until_complete(RVw(request, resource, tail)())
assert isinstance(resp, Response)
示例8: test_receive_when_target_not_in_post_data
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [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))
示例9: test_RESTView__object
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def test_RESTView__object(loop, RVobj): # noqa
request = Mock(name='request')
request.method = 'GET'
resource = Mock(name='resource')
tail = ('ta', 'il')
resp = loop.run_until_complete(RVobj(request, resource, tail)())
assert isinstance(resp, Response)
assert resp.body == b'TEST'
示例10: test_receive_when_target_does_not_resolve
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [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))
示例11: test_has_permission_fails_with_bad_user
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def test_has_permission_fails_with_bad_user(self):
permission = permissions.IsContinuousIntegrationToEdit()
user = User.objects.create(username="user")
group = Group.objects.get(
name=permissions.CONTINUOUS_INTEGRATION_GROUP_NAME)
group.user_set.add(user)
request = Mock()
request.user = user
request.method = 'POST'
view = None
self.assertTrue(permission.has_permission(request, view))
示例12: test_receive_when_general_exception_occurs
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [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))
示例13: test_any_mock_calls_comparison_order
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [as 别名]
def test_any_mock_calls_comparison_order(self):
mock = Mock()
d = datetime.now()
class Foo(object):
__qualname__ = 'AnyTest.test_any_mock_calls_comparison_order.<locals>.Foo'
def __eq__(self, other):
return False
def __ne__(self, other):
return True
for d in (datetime.now(), Foo()):
mock.reset_mock()
mock(d, foo=d, bar=d)
mock.method(d, zinga=d, alpha=d)
mock().method(a1=d, z99=d)
expected = [call(ANY, foo=ANY, bar=ANY), call.method(ANY, zinga=ANY, alpha=ANY), call(), call().method(a1=ANY, z99=ANY)]
self.assertEqual(expected, mock.mock_calls)
self.assertEqual(mock.mock_calls, expected)
示例14: test_receive_happy_path
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [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))
示例15: test_receive_when_source_does_not_contain_target
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import method [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))