Cleaned up tests to use newly-renamed Account hooks for add/remove characters.
This commit is contained in:
parent
f782cd8fc8
commit
4b80b200d8
20 changed files with 774 additions and 50 deletions
|
|
@ -236,15 +236,15 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
|
|||
|
||||
return objs
|
||||
|
||||
def add_character(self, character: "DefaultCharacter"):
|
||||
def add_character_to_playable_list(self, character: "DefaultCharacter"):
|
||||
"""
|
||||
Add a character to this account's list of playable characters.
|
||||
"""
|
||||
if character not in self.db._playable_characters:
|
||||
self.db._playable_characters.append(character)
|
||||
self.at_post_add_character(character)
|
||||
self.at_post_add_character_to_playable_list(character)
|
||||
|
||||
def at_post_add_character(self, character: "DefaultCharacter"):
|
||||
def at_post_add_character_to_playable_list(self, character: "DefaultCharacter"):
|
||||
"""
|
||||
Called after a character is added to this account's list of playable characters.
|
||||
|
||||
|
|
@ -252,15 +252,15 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
|
|||
"""
|
||||
pass
|
||||
|
||||
def remove_character(self, character):
|
||||
def remove_character_from_playable_list(self, character):
|
||||
"""
|
||||
Remove a character from this account's list of playable characters.
|
||||
"""
|
||||
if character in self.db._playable_characters:
|
||||
self.db._playable_characters.remove(character)
|
||||
self.at_post_remove_character(character)
|
||||
self.at_post_remove_character_from_playable_list(character)
|
||||
|
||||
def at_post_remove_character(self, character):
|
||||
def at_post_remove_character_from_playable_list(self, character):
|
||||
"""
|
||||
Called after a character is removed from this account's list of playable characters.
|
||||
|
||||
|
|
@ -776,7 +776,7 @@ class DefaultAccount(AccountDB, metaclass=TypeclassBase):
|
|||
)
|
||||
if character:
|
||||
# Update playable character list
|
||||
self.add_character(character)
|
||||
self.add_character_to_playable_list(character)
|
||||
|
||||
# We need to set this to have @ic auto-connect to this character
|
||||
self.db._last_puppet = character
|
||||
|
|
|
|||
|
|
@ -105,14 +105,14 @@ class TestDefaultGuest(BaseEvenniaTest):
|
|||
def test_at_server_shutdown(self):
|
||||
account, errors = DefaultGuest.create(ip=self.ip)
|
||||
self.char1.delete = MagicMock()
|
||||
account.db._playable_characters = [self.char1]
|
||||
account.add_character_to_playable_list(self.char1)
|
||||
account.at_server_shutdown()
|
||||
self.char1.delete.assert_called()
|
||||
|
||||
def test_at_post_disconnect(self):
|
||||
account, errors = DefaultGuest.create(ip=self.ip)
|
||||
self.char1.delete = MagicMock()
|
||||
account.db._playable_characters = [self.char1]
|
||||
account.add_character_to_playable_list(self.char1)
|
||||
account.at_post_disconnect()
|
||||
self.char1.delete.assert_called()
|
||||
|
||||
|
|
@ -358,19 +358,19 @@ class TestAccountPuppetDeletion(BaseEvenniaTest):
|
|||
def test_puppet_deletion(self):
|
||||
# Check for existing chars
|
||||
self.assertFalse(
|
||||
self.account.db._playable_characters, "Account should not have any chars by default."
|
||||
self.account.characters, "Account should not have any chars by default."
|
||||
)
|
||||
|
||||
# Add char1 to account's playable characters
|
||||
self.account.db._playable_characters.append(self.char1)
|
||||
self.assertTrue(self.account.db._playable_characters, "Char was not added to account.")
|
||||
self.account.add_character_to_playable_list(self.char1)
|
||||
self.assertTrue(self.account.characters, "Char was not added to account.")
|
||||
|
||||
# See what happens when we delete char1.
|
||||
self.char1.delete()
|
||||
# Playable char list should be empty.
|
||||
self.assertFalse(
|
||||
self.account.db._playable_characters,
|
||||
f"Playable character list is not empty! {self.account.db._playable_characters}",
|
||||
self.account.characters,
|
||||
f"Playable character list is not empty! {self.account.characters}",
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -387,6 +387,17 @@ class TestDefaultAccountEv(BaseEvenniaTest):
|
|||
self.assertEqual(chars, [self.char1])
|
||||
self.assertEqual(self.account.db._playable_characters, [self.char1])
|
||||
|
||||
def test_add_character_to_playable_list(self):
|
||||
self.assertEqual(self.account.characters, [])
|
||||
self.account.add_character_to_playable_list(self.char1)
|
||||
self.assertEqual(self.account.characters, [self.char1])
|
||||
|
||||
def test_remove_character_from_playable_list(self):
|
||||
self.account.add_character_to_playable_list(self.char1)
|
||||
self.assertEqual(self.account.characters, [self.char1])
|
||||
self.account.remove_character_from_playable_list(self.char1)
|
||||
self.assertEqual(self.account.characters, [])
|
||||
|
||||
def test_puppet_success(self):
|
||||
self.account.msg = MagicMock()
|
||||
with patch("evennia.accounts.accounts._MULTISESSION_MODE", 2):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue