app-MAIL-temp/tests/dashboard/test_directory.py
Son Nguyen Kim 1fc75203f2
Improve test: disable rate limit during test and avoid conflicts between tests (#1349)
* disable rate limit during test, avoid conflict between tests

* fix test
2022-10-14 16:37:49 +02:00

79 lines
2.3 KiB
Python

from flask import url_for
from app.config import MAX_NB_DIRECTORY
from app.models import Directory
from tests.utils import login
def test_create_directory(flask_client):
login(flask_client)
r = flask_client.post(
url_for("dashboard.directory"),
data={"form-name": "create", "name": "test"},
follow_redirects=True,
)
assert r.status_code == 200
assert f"Directory test is created" in r.data.decode()
assert Directory.get_by(name="test") is not None
def test_delete_directory(flask_client):
"""cannot add domain if user personal email uses this domain"""
user = login(flask_client)
directory = Directory.create(name="test", user_id=user.id, commit=True)
r = flask_client.post(
url_for("dashboard.directory"),
data={"form-name": "delete", "dir-id": directory.id},
follow_redirects=True,
)
assert r.status_code == 200
assert f"Directory test has been deleted" in r.data.decode()
assert Directory.get_by(name="test") is None
def test_create_directory_in_trash(flask_client):
user = login(flask_client)
directory = Directory.create(name="test", user_id=user.id, commit=True)
# delete the directory
r = flask_client.post(
url_for("dashboard.directory"),
data={"form-name": "delete", "dir-id": directory.id},
follow_redirects=True,
)
assert Directory.get_by(name="test") is None
# try to recreate the directory
r = flask_client.post(
url_for("dashboard.directory"),
data={"form-name": "create", "name": "test"},
follow_redirects=True,
)
assert r.status_code == 200
assert "test has been used before and cannot be reused" in r.data.decode()
def test_create_directory_out_of_quota(flask_client):
user = login(flask_client)
for i in range(
MAX_NB_DIRECTORY - Directory.filter(Directory.user_id == user.id).count()
):
Directory.create(name=f"test{i}", user_id=user.id, commit=True)
assert Directory.filter(Directory.user_id == user.id).count() == MAX_NB_DIRECTORY
flask_client.post(
url_for("dashboard.directory"),
data={"form-name": "create", "name": "test"},
follow_redirects=True,
)
# no new directory is created
assert Directory.filter(Directory.user_id == user.id).count() == MAX_NB_DIRECTORY