From 6341f9bd6fabab6431b3b4f080f407ddd02c6274 Mon Sep 17 00:00:00 2001 From: kedod Date: Mon, 4 Mar 2024 10:06:04 +0100 Subject: [PATCH] test: Use time_machine in time sensitive rate limit middleware tests (#3164) Co-authored-by: kedod --- tests/unit/test_middleware/test_rate_limit_middleware.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/unit/test_middleware/test_rate_limit_middleware.py b/tests/unit/test_middleware/test_rate_limit_middleware.py index 24ace66c69..e2a30af9a4 100644 --- a/tests/unit/test_middleware/test_rate_limit_middleware.py +++ b/tests/unit/test_middleware/test_rate_limit_middleware.py @@ -120,6 +120,7 @@ def handler() -> None: assert response.status_code == HTTP_200_OK +@travel(datetime.utcnow, tick=False) def test_exclude_patterns() -> None: @get("/excluded") def handler() -> None: @@ -145,6 +146,7 @@ def handler2() -> None: assert response.status_code == HTTP_429_TOO_MANY_REQUESTS +@travel(datetime.utcnow, tick=False) def test_exclude_opt_key() -> None: @get("/excluded", skip_rate_limiting=True) def handler() -> None: @@ -170,6 +172,7 @@ def handler2() -> None: assert response.status_code == HTTP_429_TOO_MANY_REQUESTS +@travel(datetime.utcnow, tick=False) def test_check_throttle_handler() -> None: @get("/path1") def handler1() -> None: @@ -198,6 +201,7 @@ def check_throttle_handler(request: Request[Any, Any, Any]) -> bool: assert response.status_code == HTTP_200_OK +@travel(datetime.utcnow, tick=False) async def test_rate_limiting_works_with_mounted_apps(tmpdir: "Path") -> None: # https://github.com/litestar-org/litestar/issues/781 @get("/not-excluded")