Skip to content

Commit

Permalink
Add tests for static route exemption
Browse files Browse the repository at this point in the history
  • Loading branch information
alisaifee committed Aug 22, 2023
1 parent 5fe7613 commit 53aa5c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ def t2():
assert cli.get("/t2").status_code == 429


def test_blueprint_static_exempt(extension_factory):
app, limiter = extension_factory(default_limits=["1/minute"])
bp = Blueprint("main", __name__, static_folder="static")
app.register_blueprint(bp, url_prefix="/bp")

with app.test_client() as cli:
assert cli.get("/bp/static/image.png").status_code == 200
assert cli.get("/bp/static/image.png").status_code == 200


def test_blueprint_limit_with_route_limits(extension_factory):
app, limiter = extension_factory(default_limits=["1/minute"])
bp = Blueprint("main", __name__)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_flask_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ def null():
assert "1 per 1 day" in cli.get("/").data.decode()


def test_static_exempt(extension_factory):
app, limiter = extension_factory(default_limits=["1/minute"])

@app.route("/")
def root():
return "root"

with app.test_client() as cli:
assert cli.get("/").status_code == 200
assert cli.get("/").status_code == 429
assert cli.get("/static/image.png").status_code == 200
assert cli.get("/static/image.png").status_code == 200


def test_combined_rate_limits(extension_factory):
app, limiter = extension_factory(
{ConfigVars.DEFAULT_LIMITS: "1 per hour; 10 per day"}
Expand Down

0 comments on commit 53aa5c6

Please sign in to comment.