mirror of
https://github.com/simple-login/app.git
synced 2024-09-05 10:01:30 +02:00
- add __tablename__ for all models - use sa and orm instead of db - rollback all changes in tests - remove session in @app.teardown_appcontext
58 lines
1.5 KiB
Python
58 lines
1.5 KiB
Python
from app.alias_utils import delete_alias, check_alias_prefix
|
|
from app.db import Session
|
|
from app.models import User, Alias, DeletedAlias
|
|
|
|
|
|
def test_delete_alias(flask_client):
|
|
user = User.create(
|
|
email="a@b.c",
|
|
password="password",
|
|
name="Test User",
|
|
activated=True,
|
|
commit=True,
|
|
)
|
|
alias = Alias.create(
|
|
user_id=user.id,
|
|
email="first@d1.test",
|
|
mailbox_id=user.default_mailbox_id,
|
|
commit=True,
|
|
)
|
|
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(
|
|
email="a@b.c",
|
|
password="password",
|
|
name="Test User",
|
|
activated=True,
|
|
commit=True,
|
|
)
|
|
alias = Alias.create(
|
|
user_id=user.id,
|
|
email="first@d1.test",
|
|
mailbox_id=user.default_mailbox_id,
|
|
commit=True,
|
|
)
|
|
|
|
# add the alias to global trash
|
|
Session.add(DeletedAlias(email=alias.email))
|
|
Session.commit()
|
|
|
|
delete_alias(alias, user)
|
|
assert Alias.get_by(email="first@d1.test") is None
|
|
|
|
|
|
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("+👌")
|
|
assert not check_alias_prefix("too-long" * 10)
|