Skip to content

Commit

Permalink
Add test case demonstrating use of scope in limit decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaifee committed Dec 27, 2022
1 parent f22dfbd commit b84e1ab
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_decorators.py
Expand Up @@ -74,6 +74,22 @@ def t4():
assert cli.get("/t4").status_code == 429


def test_decorated_limit_with_scope(extension_factory):
app, limiter = extension_factory()

@app.route("/t/<path:path>")
@limiter.limit("1/second", scope=lambda _: request.view_args["path"])
def t(path):
return "test"

with hiro.Timeline() as timeline:
with app.test_client() as cli:
assert cli.get("/t/1").status_code == 200
assert cli.get("/t/1").status_code == 429
assert cli.get("/t/2").status_code == 200
assert cli.get("/t/2").status_code == 429


def test_decorated_limit_with_conditional_deduction(extension_factory):
app, limiter = extension_factory()

Expand Down

0 comments on commit b84e1ab

Please sign in to comment.