Skip to content

Commit

Permalink
test: Use time_machine in time sensitive rate limit middleware tests (#…
Browse files Browse the repository at this point in the history
…3164)

Co-authored-by: kedod <kedod>
  • Loading branch information
kedod authored Mar 4, 2024
1 parent 7dc7219 commit 6341f9b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/unit/test_middleware/test_rate_limit_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6341f9b

Please sign in to comment.