mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Fixed code to pass unittests. Change script's is_valid method to correctly catch if it is checked on an object which is already deleted, as per #509.
This commit is contained in:
parent
3a6a8d5c48
commit
53b204bb76
8 changed files with 21 additions and 17 deletions
|
|
@ -333,13 +333,13 @@ class CmdCdestroy(MuxPlayerCommand):
|
|||
if not channel.access(caller, 'control'):
|
||||
self.msg("You are not allowed to do that.")
|
||||
return
|
||||
|
||||
message = "%s is being destroyed. Make sure to change your aliases." % channel
|
||||
channel_key = channel.key
|
||||
message = "%s is being destroyed. Make sure to change your aliases." % channel_key
|
||||
msgobj = create.create_message(caller, message, channel)
|
||||
channel.msg(msgobj)
|
||||
channel.delete()
|
||||
CHANNELHANDLER.update()
|
||||
self.msg("Channel '%s' was destroyed." % channel)
|
||||
self.msg("Channel '%s' was destroyed." % channel_key)
|
||||
|
||||
|
||||
class CmdCBoot(MuxPlayerCommand):
|
||||
|
|
|
|||
|
|
@ -263,4 +263,4 @@ class CmdSetHelp(MuxCommand):
|
|||
if new_entry:
|
||||
self.msg("Topic '%s' was successfully created." % topicstr)
|
||||
else:
|
||||
self.msg("Error when creating topic '%s'! Maybe it already exists?" % topicstr)
|
||||
self.msg("Error when creating topic '%s'! Contact an admin." % topicstr)
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ class Msg(SharedMemoryModel):
|
|||
|
||||
# Database manager
|
||||
objects = managers.MsgManager()
|
||||
_is_deleted = False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
SharedMemoryModel.__init__(self, *args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ class HelpEntry(SharedMemoryModel):
|
|||
|
||||
# Database manager
|
||||
objects = HelpEntryManager()
|
||||
_is_deleted = False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
SharedMemoryModel.__init__(self, *args, **kwargs)
|
||||
|
|
|
|||
|
|
@ -460,7 +460,7 @@ class Script(ScriptBase):
|
|||
Should return a boolean. The method is assumed to collect all needed
|
||||
information from its related self.obj.
|
||||
"""
|
||||
return True
|
||||
return not self._is_deleted
|
||||
|
||||
def at_start(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ class ServerConfig(WeakSharedMemoryModel):
|
|||
db_value = models.TextField(blank=True)
|
||||
|
||||
objects = ServerConfigManager()
|
||||
_is_deleted = False
|
||||
|
||||
# Wrapper properties to easily set database fields. These are
|
||||
# @property decorators that allows to access these fields using
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@ class TestScriptDB(TestCase):
|
|||
self.scr = create_script(DoNothing)
|
||||
|
||||
def tearDown(self):
|
||||
self.scr.delete()
|
||||
try:
|
||||
self.scr.delete()
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
del self.scr
|
||||
|
||||
def test_delete(self):
|
||||
|
|
@ -28,15 +31,16 @@ class TestScriptDB(TestCase):
|
|||
|
||||
def test_double_delete(self):
|
||||
"What should happen? Isn't it already deleted?"
|
||||
self.scr.delete()
|
||||
self.scr.delete()
|
||||
with self.assertRaises(ObjectDoesNotExist):
|
||||
self.scr.delete()
|
||||
self.scr.delete()
|
||||
|
||||
@unittest.skip("not implemented")
|
||||
def test___init__fails(self): # Users should be told not to do this
|
||||
with self.assertRaises(Exception):
|
||||
ScriptDB()
|
||||
#@unittest.skip("not implemented")
|
||||
#def test___init__fails(self): # Users should be told not to do this
|
||||
# - No they should not; ScriptDB() is required internally. /Griatch
|
||||
# with self.assertRaises(Exception):
|
||||
# ScriptDB()
|
||||
|
||||
@unittest.skip("not implemented")
|
||||
def test_deleted_script_fails_start(self):
|
||||
"Would it ever be necessary to start a deleted script?"
|
||||
self.scr.delete()
|
||||
|
|
@ -44,14 +48,11 @@ class TestScriptDB(TestCase):
|
|||
self.scr.start()
|
||||
# Check the script is not recreated as a side-effect
|
||||
self.assertFalse(self.scr in ScriptDB.objects.get_all_scripts())
|
||||
self.scr = create_script(DoNothing) # for tearDown()
|
||||
|
||||
@unittest.skip("not implemented")
|
||||
def test_deleted_script_is_invalid(self):
|
||||
"Can deleted scripts be said to be valid?"
|
||||
self.scr.delete()
|
||||
self.assertFalse(self.scr.is_valid()) # assertRaises? See issue #509
|
||||
self.scr = create_script(DoNothing) # for tearDown()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
|
|
@ -1206,7 +1206,7 @@ class TypedObject(SharedMemoryModel):
|
|||
_GA(self, "attributes").clear()
|
||||
if not isinstance(_GA(self, "aliases"), LazyLoadHandler):
|
||||
_GA(self, "aliases").clear()
|
||||
if not isinstance(_GA(self, "nicks"), LazyLoadHandler):
|
||||
if hasattr(self, "nicks") and not isinstance(_GA(self, "nicks"), LazyLoadHandler):
|
||||
_GA(self, "nicks").clear()
|
||||
_SA(self, "_cached_typeclass", None)
|
||||
_GA(self, "flush_from_cache")()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue