2021-11-17 17:02:31 +01:00
|
|
|
from flask import url_for
|
|
|
|
|
2021-11-18 10:33:15 +01:00
|
|
|
from app.config import MAX_NB_DIRECTORY
|
2021-11-17 17:02:31 +01:00
|
|
|
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()
|
2021-11-18 10:33:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_create_directory_out_of_quota(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
|
2022-06-30 11:40:01 +02:00
|
|
|
for i in range(MAX_NB_DIRECTORY - Directory.count()):
|
2021-11-18 10:33:15 +01:00
|
|
|
Directory.create(name=f"test{i}", user_id=user.id, commit=True)
|
|
|
|
|
|
|
|
assert Directory.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.count() == MAX_NB_DIRECTORY
|