如何从aiohttp中的应用获取视图实例?

时间:2020-02-21 16:58:28

标签: python aiohttp

我想从app中的aiohttp访问视图实例。

例如,如果有一个基于类的视图。

@routes.view('/test')
class TesView(web.View):

    async def _a(self):
        return 'return'

    async def post(self):
        self._a()
        # some code

我想在如下所示的视图实例中对_a()进行单元测试。下面的示例代码可能有语法错误,但要点是如何从应用程序获取视图实例。

async def test_testview():

    app = web.Application()
    .
    .
    .
    test_view_intance = app.xxx.xxx.xxx
    assert await test_view_instance._a() == 'return'

0 个答案:

没有答案