Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release username of a merged account #2142

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions funnel/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ def merge_accounts(current_account: _A1, other_account: _A2) -> _A1 | _A2 | None
# Push this change to the db so that the name can be re-assigned
db.session.flush()
keep_account.name = name
else:
# Release name of the merged account
merge_account.name = None
if keep_account == other_account:
# The user's currently logged in account is being discarded, so transfer
# their password over
Expand Down
62 changes: 62 additions & 0 deletions tests/unit/models/account_User_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,65 @@ def test_user_get(

lookup_by_buid = models.User.get(buid=user_rincewind.buid)
assert lookup_by_buid == user_death


def test_merge_username_delete1(
db_session: scoped_session, user_death: models.User, user_rincewind: models.User
) -> None:
"""Test for discarding merged account username."""
db_session.commit() # Add SQL timestamps
assert user_death.username
username_death = user_death.username
assert user_rincewind.username
user_kept = models.merge_accounts(user_death, user_rincewind)
db_session.commit()
assert user_kept is user_death
assert user_death.username == username_death
assert user_rincewind.username is None


def test_merge_username_delete2(
db_session: scoped_session, user_death: models.User, user_rincewind: models.User
) -> None:
"""Test for discarding merged account username (reversed order)."""
db_session.commit() # Add SQL timestamps
assert user_death.username
username_death = user_death.username
assert user_rincewind.username
user_kept = models.merge_accounts(user_rincewind, user_death)
db_session.commit()
assert user_kept is user_death
assert user_death.username == username_death
assert user_rincewind.username is None


def test_merge_username_transfer1(
db_session: scoped_session, user_death: models.User, user_rincewind: models.User
) -> None:
"""Test for transferring merged account username."""
user_death.username = None # Remove username for transfer
db_session.commit() # Add SQL timestamps
assert user_death.username is None
assert user_rincewind.username
username_rincewind = user_rincewind.username
user_kept = models.merge_accounts(user_death, user_rincewind)
db_session.commit()
assert user_kept is user_death
assert user_death.username == username_rincewind
assert user_rincewind.username is None


def test_merge_username_transfer2(
db_session: scoped_session, user_death: models.User, user_rincewind: models.User
) -> None:
"""Test for transferring merged account username (reversed order)."""
user_death.username = None # Remove username for transfer
db_session.commit() # Add SQL timestamps
assert user_death.username is None
assert user_rincewind.username
username_rincewind = user_rincewind.username
user_kept = models.merge_accounts(user_rincewind, user_death)
db_session.commit()
assert user_kept is user_death
assert user_death.username == username_rincewind
assert user_rincewind.username is None
Loading