2023-08-31 13:42:44 +02:00
|
|
|
import app.alias_utils
|
2021-10-12 14:36:47 +02:00
|
|
|
from app.db import Session
|
2021-02-17 12:56:28 +01:00
|
|
|
from app.models import (
|
|
|
|
Alias,
|
|
|
|
Mailbox,
|
|
|
|
User,
|
|
|
|
AliasMailbox,
|
|
|
|
)
|
|
|
|
from tests.utils import login
|
|
|
|
|
|
|
|
|
|
|
|
def test_alias_transfer(flask_client):
|
|
|
|
user = login(flask_client)
|
|
|
|
mb = Mailbox.create(user_id=user.id, email="mb@gmail.com", commit=True)
|
|
|
|
|
|
|
|
alias = Alias.create_new_random(user)
|
2021-10-12 14:36:47 +02:00
|
|
|
Session.commit()
|
2021-02-17 12:56:28 +01:00
|
|
|
|
|
|
|
AliasMailbox.create(alias_id=alias.id, mailbox_id=mb.id, commit=True)
|
|
|
|
|
|
|
|
new_user = User.create(
|
|
|
|
email="hey@example.com",
|
|
|
|
password="password",
|
|
|
|
activated=True,
|
|
|
|
commit=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
Mailbox.create(
|
|
|
|
user_id=new_user.id, email="hey2@example.com", verified=True, commit=True
|
|
|
|
)
|
|
|
|
|
2023-08-31 13:42:44 +02:00
|
|
|
app.alias_utils.transfer_alias(alias, new_user, new_user.mailboxes())
|
2021-02-17 12:56:28 +01:00
|
|
|
|
|
|
|
# refresh from db
|
|
|
|
alias = Alias.get(alias.id)
|
|
|
|
assert alias.user == new_user
|
|
|
|
assert set(alias.mailboxes) == set(new_user.mailboxes())
|
|
|
|
assert len(alias.mailboxes) == 2
|