Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unittest aiohttp.web applications

Given an aiohttp.web application with views like this one:

async def hello(request):
    return web.Response(body=b"Hello, world")

I'm trying to understand how to properly unit-test them.

I normally use Django's own test client when writing Django apps, and was looking for something similar for aiohttp.web. I'm not sure this is the right approach or not.

TL;DR: How do I simulate a request to an aiohttp.web app in a unittest?

like image 303
Andrés Fernández Avatar asked Dec 30 '15 15:12

Andrés Fernández


1 Answers

You may create web server and perform real HTTP requests without simulation.

See https://github.com/KeepSafe/aiohttp/blob/master/tests/test_client_functional.py for example.

like image 148
Andrew Svetlov Avatar answered Sep 30 '22 19:09

Andrew Svetlov