app-MAIL-temp/tests/dashboard/test_index.py

42 lines
1.2 KiB
Python
Raw Normal View History

2021-03-24 17:30:05 +01:00
from flask import url_for, g
from app import config
2021-03-24 17:30:05 +01:00
from app.models import (
Alias,
)
from tests.utils import login
def test_create_random_alias_success(flask_client):
2022-04-18 10:18:51 +02:00
user = login(flask_client)
assert Alias.filter(Alias.user_id == user.id).count() == 1
2021-03-24 17:30:05 +01:00
r = flask_client.post(
url_for("dashboard.index"),
data={"form-name": "create-random-email"},
follow_redirects=True,
)
assert r.status_code == 200
2022-04-18 11:17:10 +02:00
assert Alias.filter(Alias.user_id == user.id).count() == 2
2021-03-24 17:30:05 +01:00
def test_too_many_requests(flask_client):
config.DISABLE_RATE_LIMIT = False
2021-03-24 17:30:05 +01:00
login(flask_client)
# can't create more than 5 aliases in 1 minute
2022-02-06 21:37:43 +01:00
for _ in range(7):
2021-03-24 17:30:05 +01:00
r = flask_client.post(
url_for("dashboard.index"),
data={"form-name": "create-random-email"},
follow_redirects=True,
)
# to make flask-limiter work with unit test
# https://github.com/alisaifee/flask-limiter/issues/147#issuecomment-642683820
g._rate_limiting_complete = False
else:
# last request
assert r.status_code == 429
assert "Whoa, slow down there, pardner!" in str(r.data)