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


Python MagicMock.app方法代码示例

本文整理汇总了Python中unittest.mock.MagicMock.app方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.app方法的具体用法?Python MagicMock.app怎么用?Python MagicMock.app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest.mock.MagicMock的用法示例。


在下文中一共展示了MagicMock.app方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_DispatchResource

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import app [as 别名]
def test_DispatchResource(loop, app):  # noqa
    class Res(Resource):
        pass

    class CoroRes(InitCoroMixin, Resource):
        calls_ainit = 0

        async def __ainit__(self):
            self.calls_ainit += 1

    add_child(app, 'aiohttp_traversal.ext.resources.Root', 'simple', Res)
    add_child(app, Root, 'coro', CoroRes)

    request = MagicMock(name='request')
    request.app = app

    root = Root(app)

    res_simple = loop.run_until_complete(root['simple'])
    assert isinstance(res_simple, Res)
    assert res_simple.name == 'simple'
    assert res_simple.__parent__ is root

    res_coro = loop.run_until_complete(root['coro'])
    assert isinstance(res_coro, CoroRes)
    assert res_coro.name == 'coro'
    assert res_coro.__parent__ is root
    assert res_coro.calls_ainit == 1

    with pytest.raises(KeyError):
        loop.run_until_complete(root['not_exist'])
开发者ID:zzzsochi,项目名称:aiohttp_traversal,代码行数:33,代码来源:test_resources.py

示例2: test_httpresponse_controller_render_response

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import app [as 别名]
def test_httpresponse_controller_render_response(webapp):
    request = MagicMock()
    request.app = webapp
    httpresponse = server.HttpResponseController(request)
    httpresponse._renderer = Mock()

    httpresponse.render_response()
    httpresponse._renderer.assert_called_once_with(httpresponse)
开发者ID:Tygs,项目名称:tygs,代码行数:10,代码来源:test_http_server.py

示例3: create_mock_request

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import app [as 别名]
async def create_mock_request(core=None, config=None):
    config = Config(in_memory=True, config_dir='/tmp', initial=config)
    core.config = config
    request = MagicMock()
    request.app = {
        'spritzle.core': core,
        'spritzle.config': config,
    }

    return request
开发者ID:gazpachoking,项目名称:spritzle,代码行数:12,代码来源:common.py

示例4: test_httpresponse_controller_init

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import app [as 别名]
def test_httpresponse_controller_init(app):
    request = MagicMock()
    request.app = app
    httpresponse = server.HttpResponseController(request)
    assert httpresponse.template_engine is None
    assert httpresponse.status_code == 200
    assert httpresponse.reason == 'OK'
    assert httpresponse.content_type == 'text/html'
    assert httpresponse.charset == 'utf-8'
    assert httpresponse.headers == {}
    with pytest.raises(HttpResponseControllerError):
        httpresponse.render_response()
开发者ID:Tygs,项目名称:tygs,代码行数:14,代码来源:test_http_server.py

示例5: test_httpresponse_build_aiohttp_reponse

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import app [as 别名]
def test_httpresponse_build_aiohttp_reponse(webapp):
    request = MagicMock()
    request.app = webapp
    httpresponse = server.HttpResponseController(request)
    httpresponse.render_response = Mock(return_value={
        "body": b"toto",
        "content_type": "text/html",
        "status": 418
    })

    aiohttpres = httpresponse._build_aiohttp_response()

    assert isinstance(aiohttpres, Response)
    assert aiohttpres.body == b"toto"
    assert aiohttpres.content_type == "text/html"
    assert aiohttpres.status == 418
开发者ID:Tygs,项目名称:tygs,代码行数:18,代码来源:test_http_server.py

示例6: test_httpresponse_controller_template

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import app [as 别名]
def test_httpresponse_controller_template(webapp):
    request = MagicMock()
    request.app = webapp
    httpresponse = server.HttpResponseController(request)
    assert httpresponse.template_engine == webapp.components['templates']

    httpresponse.template('template_name', {'foo': 'bar'})

    assert httpresponse.context['template_name'] == 'template_name'
    context = httpresponse._renderer_data.pop('context')
    assert "res" in context and "req" in context
    assert httpresponse._renderer_data == {'foo': 'bar'}

    httpresponse.template('template_name2', {'foo2': 'bar2'})
    context = httpresponse._renderer_data.pop('context')
    assert "res" in context and "req" in context
    assert httpresponse.context['template_name'] == 'template_name2'
    assert httpresponse._renderer_data == {'foo2': 'bar2'}
开发者ID:Tygs,项目名称:tygs,代码行数:20,代码来源:test_http_server.py

示例7: asetup

# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import app [as 别名]
    async def asetup(self):
        registry = orm.mappers.Registry(
            create_metadata([self.models1, self.models2]))
        self.mapper_cls.from_model(registry, [self.models1.Test])

        app = MagicMock()
        app.cfg.DATABASES = {
            'db1': DB_URL,
            'db2': DB_URL,
        }
        del app.db
        db = await ikcms.ws_components.db.component(mappers=registry).create(app)
        async with await db() as session:
            conn1 = await session.get_connection(db.engines['db1'])
            await self.models1.reset(conn1)
            conn2 = await session.get_connection(db.engines['db2'])
            await self.models2.reset(conn2)

        class l_id(list_fields.id):
            widget = MagicMock()

        class l_title(list_fields.title):
            widget = MagicMock()

        class l_date(list_fields.Date):
            name = 'date'
            title = 'date'
            widget = MagicMock()

        class f_id(filter_fields.id):
            widget = MagicMock()

        class f_title(filter_fields.title):
            widget = MagicMock()

        class f_date(filter_fields.Date):
            name = 'date'
            title = 'date'
            widget = MagicMock()

        class f_title2(filter_fields.title):
            name = 'title2'
            title = 'title2'
            widget = MagicMock()

        class i_id(item_fields.id):
            widget = MagicMock()

            def get_initials(_self, **kwargs):
                return 50000

        class i_title(item_fields.title):
            widget = MagicMock()

            def get_initials(_self, **kwargs):
                test_kwarg = kwargs.get('test_kwarg', 'test_default')
                return '{}-{}-initials'.format(_self.name, test_kwarg)

        class i_date(item_fields.Date):
            name = 'date'
            title = 'date'
            widget = MagicMock()

            def get_initials(_self, **kwargs):
                return date(2005, 5, 5)


        class TestStream(Stream):
            max_limit = 50
            name = 'test_stream'
            title = 'test_stream_title'
            mapper_name = 'Test'
            db_id = 'db1'
            permissions = {'test_role': 'rwxcd'}

            list_fields = [
                l_id,
                l_title,
                l_date,
            ]
            filter_fields = [
                f_id,
                f_title,
                f_title2,
                f_date,
            ]
            item_fields = [
                i_id,
                i_title,
                i_date,
            ]

            def get_item_form(self, env, item=None, kwargs=None):
                kwargs = kwargs or {}
                raise_kwarg = kwargs.get('raise')
                if raise_kwarg:
                    raise raise_kwarg
                return super().get_item_form(env, item, kwargs)

            def check_perms(self, user, perms):
#.........这里部分代码省略.........
开发者ID:motor23,项目名称:cmstest,代码行数:103,代码来源:test_actions.py


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