Add to tests

This commit is contained in:
Adam Hopkins
2022-09-15 18:46:09 +03:00
parent c4c39cb082
commit 19f642b364
2 changed files with 14 additions and 3 deletions

View File

@@ -2,8 +2,10 @@ import logging
from asyncio import CancelledError
from itertools import count
from unittest.mock import Mock
from sanic.exceptions import NotFound
from sanic.middleware import Middleware, MiddlewareLocation
from sanic.request import Request
from sanic.response import HTTPResponse, json, text
@@ -318,6 +320,15 @@ def test_middleware_return_response(app):
resp1 = await request.respond()
return resp1
_, response = app.test_client.get("/")
app.test_client.get("/")
assert response_middleware_run_count == 1
assert request_middleware_run_count == 1
def test_middleware_object():
mock = Mock()
middleware = Middleware(mock)
middleware(1, 2, 3, answer=42)
mock.assert_called_once_with(1, 2, 3, answer=42)
assert middleware.order == (0, 0)