Add tests for accounts, and fix allowing user to delete friend code with active trade offers and in-game-name not being set on signup

This commit is contained in:
badblocks 2025-03-26 14:25:09 -07:00
parent 65ca344582
commit 23d334c596
6 changed files with 658 additions and 10 deletions

View file

@ -23,11 +23,14 @@ class CustomUser(AbstractUser):
def remove_default_friend_code(self, friend_code):
"""
If the given friend code is the current default,
assign another of the user's friend codes (if any) as default.
assign another of the user's friend codes as default.
Raises ValidationError if it's the only friend code.
"""
if self.default_friend_code == friend_code:
other_codes = self.friend_codes.exclude(pk=friend_code.pk)
self.default_friend_code = other_codes.first() if other_codes.exists() else None
if not other_codes.exists():
raise ValidationError("A user must always have a default friend code.")
self.default_friend_code = other_codes.first()
self.save(update_fields=["default_friend_code"])
class FriendCode(models.Model):