ccd4c9615c
Update all tests to be compatible with requests-async Cleanup testing client changes with black and isort Remove Python 3.5 and other meta doc cleanup rename pyproject and fix pep517 error Add black config to tox.ini Cleanup tests and remove aiohttp tox.ini change for easier development commands Remove aiohttp from changelog and requirements Cleanup imports and Makefile
48 lines
933 B
Python
48 lines
933 B
Python
import asyncio
|
|
|
|
from queue import Queue
|
|
from threading import Event
|
|
|
|
from sanic.response import text
|
|
|
|
|
|
def test_create_task(app):
|
|
e = Event()
|
|
|
|
async def coro():
|
|
await asyncio.sleep(0.05)
|
|
e.set()
|
|
|
|
app.add_task(coro)
|
|
|
|
@app.route("/early")
|
|
def not_set(request):
|
|
return text(e.is_set())
|
|
|
|
@app.route("/late")
|
|
async def set(request):
|
|
await asyncio.sleep(0.1)
|
|
return text(e.is_set())
|
|
|
|
request, response = app.test_client.get("/early")
|
|
assert response.body == b"False"
|
|
|
|
request, response = app.test_client.get("/late")
|
|
assert response.body == b"True"
|
|
|
|
|
|
def test_create_task_with_app_arg(app):
|
|
q = Queue()
|
|
|
|
@app.route("/")
|
|
def not_set(request):
|
|
return "hello"
|
|
|
|
async def coro(app):
|
|
q.put(app.name)
|
|
|
|
app.add_task(coro)
|
|
|
|
request, response = app.test_client.get("/")
|
|
assert q.get() == "test_create_task_with_app_arg"
|