当前位置: 首页>>代码示例>>Python>>正文


Python Mock.method方法代码示例

本文整理汇总了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
开发者ID:2gis,项目名称:httpsrvvcr,代码行数:9,代码来源:recorder_test.py

示例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))
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:9,代码来源:permissions_test.py

示例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))
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:10,代码来源:permissions_test.py

示例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'
开发者ID:zzzsochi,项目名称:aiohttp_traversal,代码行数:10,代码来源:test_views.py

示例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)())
开发者ID:zzzsochi,项目名称:aiohttp_traversal,代码行数:10,代码来源:test_views.py

示例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)())
开发者ID:zzzsochi,项目名称:aiohttp_traversal,代码行数:10,代码来源:test_views.py

示例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)
开发者ID:zzzsochi,项目名称:aiohttp_traversal,代码行数:10,代码来源:test_views.py

示例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))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:10,代码来源:test_views.py

示例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'
开发者ID:zzzsochi,项目名称:aiohttp_traversal,代码行数:11,代码来源:test_views.py

示例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))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:12,代码来源:test_views.py

示例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))
开发者ID:willjschmitt,项目名称:joulia-webserver,代码行数:13,代码来源:permissions_test.py

示例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))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:14,代码来源:test_views.py

示例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)
开发者ID:johndpope,项目名称:sims4-ai-engine,代码行数:23,代码来源:testhelpers.py

示例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))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:15,代码来源:test_views.py

示例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))
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:15,代码来源:test_views.py


注:本文中的unittest.mock.Mock.method方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。