2020-11-03 17:39:08 +08:00
|
|
|
from app.alias_utils import delete_alias, check_alias_prefix
|
2021-10-12 20:36:47 +08:00
|
|
|
from app.db import Session
|
2020-08-24 02:17:50 +08:00
|
|
|
from app.models import User, Alias, DeletedAlias
|
|
|
|
|
|
|
|
|
|
|
|
def test_delete_alias(flask_client):
|
|
|
|
user = User.create(
|
2020-09-28 23:40:30 +08:00
|
|
|
email="a@b.c",
|
|
|
|
password="password",
|
|
|
|
name="Test User",
|
|
|
|
activated=True,
|
|
|
|
commit=True,
|
2020-08-24 02:17:50 +08:00
|
|
|
)
|
|
|
|
alias = Alias.create(
|
2020-09-28 23:40:30 +08:00
|
|
|
user_id=user.id,
|
|
|
|
email="first@d1.test",
|
|
|
|
mailbox_id=user.default_mailbox_id,
|
|
|
|
commit=True,
|
2020-08-24 02:17:50 +08:00
|
|
|
)
|
|
|
|
assert Alias.get_by(email="first@d1.test")
|
|
|
|
|
|
|
|
delete_alias(alias, user)
|
|
|
|
assert Alias.get_by(email="first@d1.test") is None
|
|
|
|
assert DeletedAlias.get_by(email=alias.email)
|
|
|
|
|
|
|
|
|
|
|
|
def test_delete_alias_already_in_trash(flask_client):
|
|
|
|
"""delete an alias that's already in alias trash"""
|
|
|
|
user = User.create(
|
2020-09-28 23:40:30 +08:00
|
|
|
email="a@b.c",
|
|
|
|
password="password",
|
|
|
|
name="Test User",
|
|
|
|
activated=True,
|
|
|
|
commit=True,
|
2020-08-24 02:17:50 +08:00
|
|
|
)
|
|
|
|
alias = Alias.create(
|
2020-09-28 23:40:30 +08:00
|
|
|
user_id=user.id,
|
|
|
|
email="first@d1.test",
|
|
|
|
mailbox_id=user.default_mailbox_id,
|
|
|
|
commit=True,
|
2020-08-24 02:17:50 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
# add the alias to global trash
|
2021-10-12 20:36:47 +08:00
|
|
|
Session.add(DeletedAlias(email=alias.email))
|
|
|
|
Session.commit()
|
2020-08-24 02:17:50 +08:00
|
|
|
|
|
|
|
delete_alias(alias, user)
|
|
|
|
assert Alias.get_by(email="first@d1.test") is None
|
2020-11-03 17:39:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_check_alias_prefix(flask_client):
|
|
|
|
assert check_alias_prefix("ab-cd_")
|
|
|
|
assert not check_alias_prefix("")
|
|
|
|
assert not check_alias_prefix("éè")
|
|
|
|
assert not check_alias_prefix("a b")
|
|
|
|
assert not check_alias_prefix("+👌")
|
2020-11-18 17:38:35 +08:00
|
|
|
assert not check_alias_prefix("too-long" * 10)
|