Fixed a bug in @set. Unittests all clear again.

This commit is contained in:
Griatch 2012-04-21 18:21:38 +02:00
parent 8c3b49e704
commit 3306e36d82
3 changed files with 76 additions and 75 deletions

View file

@ -1219,7 +1219,8 @@ class CmdSetAttribute(ObjManipCommand):
except ImportError: except ImportError:
# fall back to old recursive solution (don't support nested lists/dicts) # fall back to old recursive solution (don't support nested lists/dicts)
return rec_convert(strobj.strip()) return rec_convert(strobj.strip())
else:
return strobj
def func(self): def func(self):
"Implement the set attribute - a limited form of @py." "Implement the set attribute - a limited form of @py."

View file

@ -39,14 +39,14 @@ class DefaultCmdSet(CmdSet):
self.add(system.CmdReset()) self.add(system.CmdReset())
self.add(system.CmdShutdown()) self.add(system.CmdShutdown())
self.add(system.CmdPy()) self.add(system.CmdPy())
self.add(system.CmdScripts()) self.add(system.CmdScripts())
self.add(system.CmdObjects()) self.add(system.CmdObjects())
self.add(system.CmdService()) self.add(system.CmdService())
self.add(system.CmdVersion()) self.add(system.CmdVersion())
self.add(system.CmdTime()) self.add(system.CmdTime())
self.add(system.CmdServerLoad()) self.add(system.CmdServerLoad())
#self.add(system.CmdPs()) #self.add(system.CmdPs())
# Admin commands # Admin commands
self.add(admin.CmdBoot()) self.add(admin.CmdBoot())
self.add(admin.CmdBan()) self.add(admin.CmdBan())
@ -61,19 +61,19 @@ class DefaultCmdSet(CmdSet):
self.add(building.CmdTeleport()) self.add(building.CmdTeleport())
self.add(building.CmdSetObjAlias()) self.add(building.CmdSetObjAlias())
self.add(building.CmdListCmdSets()) self.add(building.CmdListCmdSets())
self.add(building.CmdDebug()) self.add(building.CmdDebug())
self.add(building.CmdWipe()) self.add(building.CmdWipe())
self.add(building.CmdSetAttribute()) self.add(building.CmdSetAttribute())
self.add(building.CmdName()) self.add(building.CmdName())
self.add(building.CmdDesc()) self.add(building.CmdDesc())
self.add(building.CmdCpAttr()) self.add(building.CmdCpAttr())
self.add(building.CmdMvAttr()) self.add(building.CmdMvAttr())
self.add(building.CmdCopy()) self.add(building.CmdCopy())
self.add(building.CmdFind()) self.add(building.CmdFind())
self.add(building.CmdOpen()) self.add(building.CmdOpen())
self.add(building.CmdLink()) self.add(building.CmdLink())
self.add(building.CmdUnLink()) self.add(building.CmdUnLink())
self.add(building.CmdCreate()) self.add(building.CmdCreate())
self.add(building.CmdDig()) self.add(building.CmdDig())
self.add(building.CmdTunnel()) self.add(building.CmdTunnel())
self.add(building.CmdDestroy()) self.add(building.CmdDestroy())
@ -82,7 +82,7 @@ class DefaultCmdSet(CmdSet):
self.add(building.CmdLock()) self.add(building.CmdLock())
self.add(building.CmdScript()) self.add(building.CmdScript())
self.add(building.CmdHome()) self.add(building.CmdHome())
# Batchprocessor commands # Batchprocessor commands
self.add(batchprocess.CmdBatchCommands()) self.add(batchprocess.CmdBatchCommands())
self.add(batchprocess.CmdBatchCode()) self.add(batchprocess.CmdBatchCode())

View file

@ -28,8 +28,8 @@ from django.contrib.auth.models import User
from src.players.models import PlayerDB from src.players.models import PlayerDB
from src.objects.models import ObjectDB from src.objects.models import ObjectDB
#------------------------------------------------------------ #------------------------------------------------------------
# Command testing # Command testing
# ------------------------------------------------------------ # ------------------------------------------------------------
# print all feedback from test commands (can become very verbose!) # print all feedback from test commands (can become very verbose!)
@ -38,10 +38,10 @@ VERBOSE = False
def cleanup(): def cleanup():
User.objects.all().delete() User.objects.all().delete()
PlayerDB.objects.all().delete() PlayerDB.objects.all().delete()
ObjectDB.objects.all().delete() ObjectDB.objects.all().delete()
Channel.objects.all().delete() Channel.objects.all().delete()
Msg.objects.all().delete() Msg.objects.all().delete()
PlayerChannelConnection.objects.all().delete() PlayerChannelConnection.objects.all().delete()
ExternalChannelConnection.objects.all().delete() ExternalChannelConnection.objects.all().delete()
ServerConfig.objects.all().delete() ServerConfig.objects.all().delete()
@ -63,25 +63,25 @@ class FakeSessionHandler(sessionhandler.ServerSessionHandler):
SESSIONS = FakeSessionHandler() SESSIONS = FakeSessionHandler()
class FakeSession(serversession.ServerSession): class FakeSession(serversession.ServerSession):
""" """
A fake session that A fake session that
implements dummy versions of the real thing; this is needed to implements dummy versions of the real thing; this is needed to
mimic a logged-in player. mimic a logged-in player.
""" """
protocol_key = "TestProtocol" protocol_key = "TestProtocol"
sessdict = {'protocol_key':'telnet', 'address':('0.0.0.0','5000'), 'sessid':2, 'uid':2, 'uname':None, sessdict = {'protocol_key':'telnet', 'address':('0.0.0.0','5000'), 'sessid':2, 'uid':2, 'uname':None,
'logged_in':False, 'cid':None, 'ndb':{}, 'encoding':'utf-8', 'logged_in':False, 'cid':None, 'ndb':{}, 'encoding':'utf-8',
'conn_time':time.time(), 'cmd_last':time.time(), 'cmd_last_visible':time.time(), 'cmd_total':1} 'conn_time':time.time(), 'cmd_last':time.time(), 'cmd_last_visible':time.time(), 'cmd_total':1}
def connectionMade(self): def connectionMade(self):
self.load_sync_data(self.sessdict) self.load_sync_data(self.sessdict)
self.sessionhandler = SESSIONS self.sessionhandler = SESSIONS
def disconnectClient(self): def disconnectClient(self):
pass pass
def lineReceived(self, raw_string): def lineReceived(self, raw_string):
pass pass
def msg(self, message, data=None): def msg(self, message, data=None):
if message.startswith("Traceback (most recent call last):"): if message.startswith("Traceback (most recent call last):"):
#retval = "Traceback last line: %s" % message.split('\n')[-4:] #retval = "Traceback last line: %s" % message.split('\n')[-4:]
raise AssertionError(message) raise AssertionError(message)
@ -97,7 +97,7 @@ class FakeSession(serversession.ServerSession):
rstring = rstring.strip() rstring = rstring.strip()
if not message_noansi.startswith(rstring): if not message_noansi.startswith(rstring):
sep1 = "\n" + "="*30 + "Wanted message" + "="*34 + "\n" sep1 = "\n" + "="*30 + "Wanted message" + "="*34 + "\n"
sep2 = "\n" + "="*30 + "Returned message" + "="*32 + "\n" sep2 = "\n" + "="*30 + "Returned message" + "="*32 + "\n"
sep3 = "\n" + "="*78 sep3 = "\n" + "="*78
retval = sep1 + rstring + sep2 + message_noansi + sep3 retval = sep1 + rstring + sep2 + message_noansi + sep3
raise AssertionError(retval) raise AssertionError(retval)
@ -115,13 +115,13 @@ class CommandTest(TestCase):
NOMANGLE = True # mangle command input for extra testing NOMANGLE = True # mangle command input for extra testing
def setUp(self): def setUp(self):
"sets up the testing environment" "sets up the testing environment"
#ServerConfig.objects.conf("default_home", 2) #ServerConfig.objects.conf("default_home", 2)
self.addCleanup(cleanup) self.addCleanup(cleanup)
self.room1 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room1") self.room1 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room1")
self.room2 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room2") self.room2 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room2")
# create a faux player/character for testing. # create a faux player/character for testing.
self.char1 = create.create_player("TestChar", "testplayer@test.com", "testpassword", character_location=self.room1) self.char1 = create.create_player("TestChar", "testplayer@test.com", "testpassword", character_location=self.room1)
self.char1.player.user.is_superuser = True self.char1.player.user.is_superuser = True
@ -133,28 +133,28 @@ class CommandTest(TestCase):
sess.session_login(self.char1.player) sess.session_login(self.char1.player)
# create second player # create second player
self.char2 = create.create_player("TestChar2", "testplayer2@test.com", "testpassword2", character_location=self.room1) self.char2 = create.create_player("TestChar2", "testplayer2@test.com", "testpassword2", character_location=self.room1)
self.char2.player.user.is_superuser = False self.char2.player.user.is_superuser = False
self.char2.lock_storage = "" self.char2.lock_storage = ""
self.char2.locks = LockHandler(self.char2) self.char2.locks = LockHandler(self.char2)
self.char2.ndb.return_string = None self.char2.ndb.return_string = None
sess2 = FakeSession() sess2 = FakeSession()
sess2.connectionMade() sess2.connectionMade()
sess2.session_login(self.char2.player) sess2.session_login(self.char2.player)
# A non-player-controlled character # A non-player-controlled character
self.char3 = create.create_object(settings.BASE_CHARACTER_TYPECLASS, key="TestChar3", location=self.room1) self.char3 = create.create_object(settings.BASE_CHARACTER_TYPECLASS, key="TestChar3", location=self.room1)
# create some objects # create some objects
self.obj1 = create.create_object(settings.BASE_OBJECT_TYPECLASS, key="obj1", location=self.room1) self.obj1 = create.create_object(settings.BASE_OBJECT_TYPECLASS, key="obj1", location=self.room1)
self.obj2 = create.create_object(settings.BASE_OBJECT_TYPECLASS, key="obj2", location=self.room1) self.obj2 = create.create_object(settings.BASE_OBJECT_TYPECLASS, key="obj2", location=self.room1)
self.exit1 = create.create_object(settings.BASE_EXIT_TYPECLASS, key="exit1", location=self.room1) self.exit1 = create.create_object(settings.BASE_EXIT_TYPECLASS, key="exit1", location=self.room1)
self.exit2 = create.create_object(settings.BASE_EXIT_TYPECLASS, key="exit2", location=self.room2) self.exit2 = create.create_object(settings.BASE_EXIT_TYPECLASS, key="exit2", location=self.room2)
def tearDown(self): def tearDown(self):
"Cleans up testing environment after test has run." "Cleans up testing environment after test has run."
User.objects.all().delete() User.objects.all().delete()
PlayerDB.objects.all().delete() PlayerDB.objects.all().delete()
ObjectDB.objects.all().delete() ObjectDB.objects.all().delete()
Channel.objects.all().delete() Channel.objects.all().delete()
Msg.objects.all().delete() Msg.objects.all().delete()
PlayerChannelConnection.objects.all().delete() PlayerChannelConnection.objects.all().delete()
ExternalChannelConnection.objects.all().delete() ExternalChannelConnection.objects.all().delete()
ServerConfig.objects.all().delete() ServerConfig.objects.all().delete()
@ -163,7 +163,7 @@ class CommandTest(TestCase):
""" """
Obtain a cmd instance from a class and an input string Obtain a cmd instance from a class and an input string
Note: This does not make use of the cmdhandler functionality. Note: This does not make use of the cmdhandler functionality.
""" """
cmd = cmd_class() cmd = cmd_class()
cmd.caller = self.char1 cmd.caller = self.char1
cmd.cmdstring = cmd_class.key cmd.cmdstring = cmd_class.key
@ -171,22 +171,22 @@ class CommandTest(TestCase):
cmd.cmdset = None cmd.cmdset = None
cmd.obj = self.char1 cmd.obj = self.char1
return cmd return cmd
def execute_cmd(self, raw_string, wanted_return_string=None, nomangle=False): def execute_cmd(self, raw_string, wanted_return_string=None, nomangle=False):
""" """
Creates the command through faking a normal command call; Creates the command through faking a normal command call;
This also mangles the input in various ways to test if the command This also mangles the input in various ways to test if the command
will be fooled. will be fooled.
""" """
if not nomangle and not VERBOSE and not self.NOMANGLE: if not nomangle and not VERBOSE and not self.NOMANGLE:
# only mangle if not VERBOSE, to make fewer return lines # only mangle if not VERBOSE, to make fewer return lines
test1 = re.sub(r'\s', '', raw_string) # remove all whitespace inside it test1 = re.sub(r'\s', '', raw_string) # remove all whitespace inside it
test2 = "%s/åäö öäö;-:$£@*~^' 'test" % raw_string # inserting weird characters in call test2 = "%s/åäö öäö;-:$£@*~^' 'test" % raw_string # inserting weird characters in call
test3 = "%s %s" % (raw_string, raw_string) # multiple calls test3 = "%s %s" % (raw_string, raw_string) # multiple calls
self.char1.execute_cmd(test1) self.char1.execute_cmd(test1)
self.char1.execute_cmd(test2) self.char1.execute_cmd(test2)
self.char1.execute_cmd(test3) self.char1.execute_cmd(test3)
# actual call, we potentially check so return is ok. # actual call, we potentially check so return is ok.
self.char1.ndb.return_string = wanted_return_string self.char1.ndb.return_string = wanted_return_string
try: try:
self.char1.execute_cmd(raw_string) self.char1.execute_cmd(raw_string)
@ -197,9 +197,9 @@ class CommandTest(TestCase):
class BuildTest(CommandTest): class BuildTest(CommandTest):
""" """
We need to turn of mangling for build commands since We need to turn of mangling for build commands since
it creates arbitrary objects that mess up tests later. it creates arbitrary objects that mess up tests later.
""" """
NOMANGLE = True NOMANGLE = True
@ -232,43 +232,43 @@ class TestPose(CommandTest):
self.execute_cmd("pose is testing","TestChar is testing") self.execute_cmd("pose is testing","TestChar is testing")
class TestNick(CommandTest): class TestNick(CommandTest):
def test_call(self): def test_call(self):
self.char1.player.user.is_superuser = False self.char1.player.user.is_superuser = False
self.execute_cmd("nickname testalias = testaliasedstring1") self.execute_cmd("nickname testalias = testaliasedstring1")
self.execute_cmd("nickname/player testalias = testaliasedstring2") self.execute_cmd("nickname/player testalias = testaliasedstring2")
self.execute_cmd("nickname/object testalias = testaliasedstring3") self.execute_cmd("nickname/object testalias = testaliasedstring3")
self.assertEqual(u"testaliasedstring1", self.char1.nicks.get("testalias")) self.assertEqual(u"testaliasedstring1", self.char1.nicks.get("testalias"))
self.assertEqual(u"testaliasedstring2", self.char1.nicks.get("testalias",nick_type="player")) self.assertEqual(u"testaliasedstring2", self.char1.nicks.get("testalias",nick_type="player"))
self.assertEqual(u"testaliasedstring3", self.char1.nicks.get("testalias",nick_type="object")) self.assertEqual(u"testaliasedstring3", self.char1.nicks.get("testalias",nick_type="object"))
class TestGet(CommandTest): class TestGet(CommandTest):
def test_call(self): def test_call(self):
self.obj1.location = self.room1 self.obj1.location = self.room1
self.execute_cmd("get obj1", "You pick up obj1.") self.execute_cmd("get obj1", "You pick up obj1.")
class TestDrop(CommandTest): class TestDrop(CommandTest):
def test_call(self): def test_call(self):
self.obj1.location = self.char1 self.obj1.location = self.char1
self.execute_cmd("drop obj1", "You drop obj1.") self.execute_cmd("drop obj1", "You drop obj1.")
class TestWho(CommandTest): class TestWho(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("who") self.execute_cmd("who")
class TestSay(CommandTest): class TestSay(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("say Hello", 'You say, "Hello') self.execute_cmd("say Hello", 'You say, "Hello')
class TestAccess(CommandTest): class TestAccess(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("access") self.execute_cmd("access")
class TestEncoding(CommandTest): class TestEncoding(CommandTest):
def test_call(self): def test_call(self):
global NOMANGLE global NOMANGLE
NOMANGLE = True NOMANGLE = True
self.char1.db.encoding="utf-8" self.char1.db.encoding="utf-8"
self.execute_cmd("@encoding", "Default encoding:") self.execute_cmd("@encoding", "Default encoding:")
NOMANGLE = False NOMANGLE = False
# help.py command tests # help.py command tests
class TestHelpSystem(CommandTest): class TestHelpSystem(CommandTest):
def test_call(self): def test_call(self):
self.NOMANGLE = True self.NOMANGLE = True
sep = "-"*78 + "\n" sep = "-"*78 + "\n"
self.execute_cmd("@help/add TestTopic,TestCategory = Test1", ) self.execute_cmd("@help/add TestTopic,TestCategory = Test1", )
self.execute_cmd("help TestTopic",sep + "Help topic for Testtopic\nTest1" + "\n" + sep) self.execute_cmd("help TestTopic",sep + "Help topic for Testtopic\nTest1" + "\n" + sep)
@ -327,12 +327,12 @@ class TestPerm(CommandTest):
# cannot test this here; screws up the test suite # cannot test this here; screws up the test suite
#class TestPuppet(CommandTest): #class TestPuppet(CommandTest):
# def test_call(self): # def test_call(self):
# self.execute_cmd("@puppet TestChar3", "You now control TestChar3.") # self.execute_cmd("@puppet TestChar3", "You now control TestChar3.")
# self.execute_cmd("@puppet TestChar", "You now control TestChar.") # self.execute_cmd("@puppet TestChar", "You now control TestChar.")
class TestWall(CommandTest): class TestWall(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("@wall = This is a test message", "TestChar shouts") self.execute_cmd("@wall = This is a test message", "TestChar shouts")
# building.py command tests # building.py command tests
@ -442,14 +442,14 @@ class TestScript(BuildTest):
def test_call(self): def test_call(self):
self.execute_cmd("@script TestChar = examples.bodyfunctions.BodyFunctions", "Script successfully added") self.execute_cmd("@script TestChar = examples.bodyfunctions.BodyFunctions", "Script successfully added")
# Comms commands # Comms commands
class TestChannelCreate(CommandTest): class TestChannelCreate(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel") self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
self.execute_cmd("testchan1 Hello", "[testchannel1] TestChar: Hello") self.execute_cmd("testchan1 Hello", "[testchannel1] TestChar: Hello")
class TestAddCom(CommandTest): class TestAddCom(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'") self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'")
self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel") self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
self.execute_cmd("addcom chan1 = testchannel1") self.execute_cmd("addcom chan1 = testchannel1")
@ -472,32 +472,32 @@ class TestAllCom(CommandTest):
self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel") self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
self.execute_cmd("allcom off") self.execute_cmd("allcom off")
self.execute_cmd("allcom on") self.execute_cmd("allcom on")
self.execute_cmd("allcom destroy") self.execute_cmd("allcom destroy")
class TestChannels(CommandTest): class TestChannels(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel") self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'") self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'")
class TestCBoot(CommandTest): class TestCBoot(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'") self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'")
self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel") self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
self.execute_cmd("addcom testchan = testchannel1") self.execute_cmd("addcom testchan = testchannel1")
self.execute_cmd("@cboot testchannel1 = TestChar", "TestChar boots TestChar from channel.") self.execute_cmd("@cboot testchannel1 = TestChar", "TestChar boots TestChar from channel.")
class TestCemit(CommandTest): class TestCemit(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel") self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
self.execute_cmd("@cemit testchan1 = Testing!", "[testchannel1] Testing!") self.execute_cmd("@cemit testchan1 = Testing!", "[testchannel1] Testing!")
class TestCwho(CommandTest): class TestCwho(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel") self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
self.execute_cmd("@cwho testchan1b", "Channel subscriptions") self.execute_cmd("@cwho testchan1b", "Channel subscriptions")
# OOC commands # OOC commands
#class TestOOC_and_IC(CommandTest): # can't be tested it seems, causes errors in other commands (?) #class TestOOC_and_IC(CommandTest): # can't be tested it seems, causes errors in other commands (?)
# def test_call(self): # def test_call(self):
# self.execute_cmd("@ooc", "\nYou go OOC.") # self.execute_cmd("@ooc", "\nYou go OOC.")
# self.execute_cmd("@ic", "\nYou become TestChar") # self.execute_cmd("@ic", "\nYou become TestChar")
# Unloggedin commands # Unloggedin commands
# these cannot be tested from here. # these cannot be tested from here.