Implemented unittests for all default commands in a new and much faster way.

This commit is contained in:
Griatch 2013-05-12 19:53:19 +02:00
parent a6840aff15
commit bd9421d4b0
9 changed files with 133 additions and 528 deletions

View file

@ -427,7 +427,7 @@ class CmdEmit(MuxCommand):
else:
caller.msg("Emitted to %s." % objname)
else:
caller.msg("You are not allowed to send to %s." % objname)
caller.msg("You are not allowed to emit to %s." % objname)
@ -547,10 +547,6 @@ class CmdPerm(MuxCommand):
# add a new permission
permissions = obj.permissions
caller.permissions
for perm in self.rhslist:
# don't allow to set a permission higher in the hierarchy than the one the
@ -589,4 +585,5 @@ class CmdWall(MuxCommand):
self.caller.msg("Usage: @wall <message>")
return
message = "%s shouts \"%s\"" % (self.caller.name, self.args)
self.msg("Announcing to all connected players ...")
SESSIONS.announce_all(message)

View file

@ -10,7 +10,7 @@ containing a list of in-game commands and executes them in sequence as
if they had been entered in the game (including permission checks
etc).
Example batch-command file: game/gamesrc/commands/examples/example_batch_cmd.ev
Example batch-command file: game/gamesrc/commands/examples/batch_cmds.ev
Batch-code is a full-fledged python code interpreter that reads blocks
of python code (*.py) and executes them in sequence. This allows for
@ -18,7 +18,7 @@ much more power than Batch-command, but requires knowing Python and
the Evennia API. It is also a severe security risk and should
therefore always be limited to superusers only.
Example batch-code file: game/gamesrc/commands/examples/example_batch_code.py
Example batch-code file: game/gamesrc/commands/examples/batch_code.py
"""
from traceback import format_exc

View file

@ -1643,9 +1643,9 @@ class CmdExamine(ObjManipCommand):
if things:
string += "\n{wContents{n: %s" % ", ".join([cont.name for cont in obj.contents
if cont not in exits and cont not in pobjs])
separater = "="*78
separator = "-"*78
#output info
return '%s\n%s\n%s' % ( separater, string.strip(), separater )
return '%s\n%s\n%s' % ( separator, string.strip(), separator )
def func(self):
"Process command"

View file

@ -166,7 +166,7 @@ class CmdDelCom(MuxCommand):
else:
self.msg("You had no such alias defined for this channel.")
class CmdAllCom(MuxCommand):
class CmdAllCom(MuxPlayerCommand):
"""
allcom - operate on all channels
@ -227,7 +227,7 @@ class CmdAllCom(MuxCommand):
# wrong input
self.msg("Usage: allcom on | off | who | clear")
class CmdChannels(MuxCommand):
class CmdChannels(MuxPlayerCommand):
"""
@clist
@ -280,7 +280,7 @@ class CmdChannels(MuxCommand):
chan.desc])
caller.msg("\n{wAvailable channels{n (use {wcomlist{n,{waddcom{n and {wdelcom{n to manage subscriptions):\n%s" % comtable)
class CmdCdestroy(MuxCommand):
class CmdCdestroy(MuxPlayerCommand):
"""
@cdestroy
@ -316,7 +316,7 @@ class CmdCdestroy(MuxCommand):
CHANNELHANDLER.update()
self.msg("%s was destroyed." % channel)
class CmdCBoot(MuxCommand):
class CmdCBoot(MuxPlayerCommand):
"""
@cboot
@ -375,7 +375,7 @@ class CmdCBoot(MuxCommand):
channel.disconnect_from(player)
CHANNELHANDLER.update()
class CmdCemit(MuxCommand):
class CmdCemit(MuxPlayerCommand):
"""
@cemit - send a message to channel
@ -422,7 +422,7 @@ class CmdCemit(MuxCommand):
string = "Sent to channel %s: %s" % (channel.key, message)
self.msg(string)
class CmdCWho(MuxCommand):
class CmdCWho(MuxPlayerCommand):
"""
@cwho
@ -458,7 +458,7 @@ class CmdCWho(MuxCommand):
string += " <None>"
self.msg(string.strip())
class CmdChannelCreate(MuxCommand):
class CmdChannelCreate(MuxPlayerCommand):
"""
@ccreate
channelcreate
@ -505,7 +505,7 @@ class CmdChannelCreate(MuxCommand):
self.msg("Created channel %s and connected to it." % new_chan.key)
class CmdCset(MuxCommand):
class CmdCset(MuxPlayerCommand):
"""
@cset - changes channel access restrictions
@ -551,7 +551,7 @@ class CmdCset(MuxCommand):
self.msg(string)
class CmdCdesc(MuxCommand):
class CmdCdesc(MuxPlayerCommand):
"""
@cdesc - set channel description
@ -579,8 +579,8 @@ class CmdCdesc(MuxCommand):
self.msg("Channel '%s' not found." % self.lhs)
return
#check permissions
if not caller.access(caller, 'control'):
self.msg("You cant admin this channel.")
if not channel.access(caller, 'control'):
self.msg("You cannot admin this channel.")
return
# set the description
channel.desc = self.rhs

View file

@ -24,8 +24,8 @@ from src.utils import utils, create, search, prettytable
from settings import MAX_NR_CHARACTERS, MULTISESSION_MODE
# limit symbol import for API
__all__ = ("CmdOOCLook", "CmdIC", "CmdOOC", "CmdPassword", "CmdQuit",
"CmdEncoding", "CmdSessions", "CmdWho", "CmdColorTest")
__all__ = ("CmdOOCLook", "CmdIC", "CmdOOC", "CmdPassword", "CmdQuit", "CmdCharCreate",
"CmdEncoding", "CmdSessions", "CmdWho", "CmdColorTest", "CmdQuell")
# force max nr chars to 1 if mode is 0 or 1
MAX_NR_CHARACTERS = MULTISESSION_MODE < 2 and 1 or MAX_NR_CHARACTERS

View file

@ -12,51 +12,48 @@ main test suite started with
"""
#import re, time
#from django.conf import settings
#from src.utils import create, ansi
#from src.server import serversession, sessionhandler
#from src.locks.lockhandler import LockHandler
#from src.server.models import ServerConfig
#from src.comms.models import Channel, Msg, PlayerChannelConnection, ExternalChannelConnection
#from django.contrib.auth.models import User
#from src.players.models import PlayerDB
#from src.objects.models import ObjectDB
import re
from django.conf import settings
from django.utils.unittest import TestCase
from src.players.player import Player
#from src.objects.Objects import Character
from src.utils import create, utils, ansi
_RE = re.compile(r"^\+|-+\+|\+-+|--*|\|", re.MULTILINE)
#------------------------------------------------------------
# Command testing
# ------------------------------------------------------------
class TestPlayer(Player):
class TestPlayerClass(Player):
def msg(self, message, **kwargs):
"test message"
#print "in testing msg():", message
if not self.ndb.stored_msg:
self.ndb.stored_msg = []
self.ndb.stored_msg.append(message)
def _get_superuser(self):
"test with superuser flag"
return self.ndb.is_superuser
is_superuser = property(_get_superuser)
class CommandTest(TestCase):
"""
Tests a command
"""
CID = 0
CID = 0 # we must set a different CID in every test to avoid unique-name collisions creating the objects
def setUp(self):
"sets up testing environment"
self.room1 = create.create_object("src.objects.objects.Room", key="Room%i"%self.CID)
self.room1.db.desc = "room_desc"
self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib"%self.CID)
self.obj1 = create.create_object("src.objects.objects.Object", key="Obj%i"%self.CID, location=self.room1, home=self.room1)
self.obj2 = create.create_object("src.objects.objects.Object", key="Obj%ib"%self.CID, location=self.room1, home=self.room1)
self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID)
self.obj1 = create.create_object("src.objects.objects.Object", key="Obj%i" % self.CID, location=self.room1, home=self.room1)
self.obj2 = create.create_object("src.objects.objects.Object", key="Obj%ib" % self.CID, location=self.room1, home=self.room1)
self.char1 = create.create_object("src.objects.objects.Character", key="Char%i" % self.CID, location=self.room1, home=self.room1)
self.char2 = create.create_object("src.objects.objects.Character", key="Char%ib" % self.CID, location=self.room1, home=self.room1)
self.script = create.create_script("src.scripts.scripts.Script", key="Script%i"%self.CID)
self.player = create.create_player("TestPlayer%i"%self.CID, "test@test.com", "testpassword", typeclass=TestPlayer)
self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID)
self.player = create.create_player("TestPlayer%i" % self.CID, "test@test.com", "testpassword", typeclass=TestPlayerClass)
self.player2 = create.create_player("TestPlayer%ib" % self.CID, "test@test.com", "testpassword", typeclass=TestPlayerClass)
self.player.permissions = "Immortals"
self.char1.player = self.player
self.char1.sessid = 1
@ -71,7 +68,6 @@ class CommandTest(TestCase):
The msgreturn value is compared to eventual
output sent to caller.msg in the game
"""
cmdobj.caller = self.char1
cmdobj.cmdstring = cmdobj.key
cmdobj.args = args
@ -85,20 +81,22 @@ class CommandTest(TestCase):
cmdobj.parse()
cmdobj.func()
cmdobj.at_post_cmd()
for msg in self.char1.player.ndb.stored_msg:
# clean out prettytable sugar
pass
returned_msg = "|".join(self.char1.player.ndb.stored_msg)
# clean out prettytable sugar
returned_msg = "|".join(_RE.sub("", mess) for mess in self.char1.player.ndb.stored_msg)
#returned_msg = "|".join(self.char1.player.ndb.stored_msg)
returned_msg = ansi.parse_ansi(returned_msg, strip_ansi=noansi).strip()
if msg != None and not returned_msg.startswith(msg.strip()):
sep1 = "\n" + "="*30 + "Wanted message" + "="*34 + "\n"
sep2 = "\n" + "="*30 + "Returned message" + "="*32 + "\n"
sep3 = "\n" + "="*78
retval = sep1 + msg.strip() + sep2 + returned_msg + sep3
raise AssertionError(retval)
if msg != None:
if msg == "" and returned_msg or not returned_msg.startswith(msg.strip()):
sep1 = "\n" + "="*30 + "Wanted message" + "="*34 + "\n"
sep2 = "\n" + "="*30 + "Returned message" + "="*32 + "\n"
sep3 = "\n" + "="*78
retval = sep1 + msg.strip() + sep2 + returned_msg + sep3
raise AssertionError(retval)
#------------------------------------------------------------
# Individual module Tests
#------------------------------------------------------------
from src.commands.default import general
class TestGeneral(CommandTest):
@ -106,34 +104,28 @@ class TestGeneral(CommandTest):
def test_cmds(self):
self.call(general.CmdLook(), "here", "Room1\n room_desc")
self.call(general.CmdHome(), "", "You are already home")
self.call(general.CmdPassword(), "testpassword = testpassword", "")
self.call(general.CmdInventory(), "", "You are not carrying anything.")
self.call(general.CmdPose(), "looks around", "Caller1 looks around")
self.call(general.CmdPose(), "looks around", "Char1 looks around")
self.call(general.CmdHome(), "", "You are already home")
self.call(general.CmdNick(), "testalias = testaliasedstring1", "Nick set:")
self.call(general.CmdNick(), "/player testalias = testaliasedstring2", "Nick set:")
self.call(general.CmdNick(), "/object testalias = testaliasedstring3", "Nick set:")
self.assertEqual(u"testaliasedstring1", self.caller.nicks.get("testalias"))
self.assertEqual(u"testaliasedstring2", self.caller.nicks.get("testalias", nick_type="player"))
self.assertEqual(u"testaliasedstring3", self.caller.nicks.get("testalias", nick_type="object"))
self.assertEqual(u"testaliasedstring1", self.char1.nicks.get("testalias"))
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.call(general.CmdGet(), "Obj1", "You pick up Obj1.")
self.call(general.CmdDrop(), "Obj1", "You drop Obj1.")
self.call(general.CmdWho(), "", "Player Name")
self.call(general.CmdSay(), "Testing", "You say, \"Testing\"")
self.call(general.CmdAccess(), "", "Permission Hierarchy (climbing):")
#self.call(general.CmdEncoding(), "", "Default encoding:")
#self.call(general.CmdQuit(), "", "You are already home")
from src.commands.default import help
from src.commands.default.cmdset_character import CharacterCmdSet
class TestHelp(CommandTest):
CID = 2
def test_cmds(self):
sep = "-"*78 + "\n"
self.call(help.CmdHelp(), "", sep + " Command help entries", cmdset=CharacterCmdSet())
self.call(help.CmdHelp(), "", "Command help entries", cmdset=CharacterCmdSet())
self.call(help.CmdSetHelp(), "testhelp, General = This is a test", "Topic 'testhelp' was successfully created.")
self.call(help.CmdHelp(), "testhelp", sep + "Help topic for testhelp", cmdset=CharacterCmdSet())
self.call(help.CmdHelp(), "testhelp", "Help topic for testhelp", cmdset=CharacterCmdSet())
from src.commands.default import system
class TestSystem(CommandTest):
@ -143,473 +135,89 @@ class TestSystem(CommandTest):
# since the server is not running during these tests.
self.call(system.CmdPy(), "1+2", ">>> 1+2|<<< 3")
self.call(system.CmdScripts(), "", "id ")
self.call(system.CmdObjects(), "", "Database totals:")
self.call(system.CmdObjects(), "", "Object subtype totals")
self.call(system.CmdAbout(), "", None)
self.call(system.CmdServerLoad(), "", "Server load (1 min):")
self.call(system.CmdServerLoad(), "", "Server CPU and Memory load:")
from src.commands.default import admin
class TestAdmin(CommandTest):
CID = 4
def test_cmds(self):
# not testing CmdBoot, CmdDelPlayer, CmdNewPassword
self.call(admin.CmdEmit(), "Char4 = Test", "Test|Emitted to Char4.")
self.call(admin.CmdPerm(), "Obj1 = Builders", "Permission 'Builders' given to Obj1.")
self.call(admin.CmdWall(), "Test", "Caller4 shouts \"Test\"")
self.call(admin.CmdEmit(), "Char4b = Test", "Emitted to Char4b.")
self.call(admin.CmdPerm(), "Obj4 = Builders", "Permission 'Builders' given to Obj4.")
self.call(admin.CmdWall(), "Test", "Announcing to all connected players ...")
self.call(admin.CmdPerm(), "Char4b = Builders","Permission 'Builders' given to Char4b.")
self.call(admin.CmdBan(), "Char4", "NameBan char4 was added.")
from src.commands.default import player
class TestPlayer(CommandTest):
CID = 5
def test_cmds(self):
self.call(player.CmdOOCLook(), "", "Account TestPlayer5 (you are OutofCharacter)")
self.call(player.CmdIC(), "Char5","Char5 is now acted from another")
self.call(player.CmdOOC(), "", "You are already")
self.call(player.CmdPassword(), "testpassword = testpassword", "Password changed.")
self.call(player.CmdEncoding(), "", "Default encoding:")
self.call(player.CmdWho(), "", "Players:")
self.call(player.CmdQuit(), "", "Quitting. Hope to see you soon again.")
self.call(player.CmdSessions(), "", "Your current session(s):")
self.call(player.CmdColorTest(), "ansi", "ANSI colors:")
self.call(player.CmdCharCreate(), "Test1=Test char","Created new character Test1. Use @ic Test1 to enter the game")
self.call(player.CmdQuell(), "", "Quelling Player permissions (Immortals).")
from src.commands.default import building
class TestBuilding(CommandTest):
CID = 6
def test_cmds(self):
self.call(building.CmdCreate(), "/drop TestObj1", "You create a new Object: TestObj1.")
self.call(building.CmdSetObjAlias(), "TestObj1 = TestObj1b","Aliases for 'TestObj1' are now set to testobj1b.")
self.call(building.CmdCopy(), "TestObj1 = TestObj2;TestObj2b, TestObj3;TestObj3b", "Copied TestObj1 to 'TestObj3' (aliases: ['TestObj3b']")
self.call(building.CmdSetAttribute(), "Obj6/test1=\"value1\"", "Created attribute Obj6/test1 = \"value1\"")
self.call(building.CmdSetAttribute(), "Obj6b/test2=\"value2\"", "Created attribute Obj6b/test2 = \"value2\"")
self.call(building.CmdMvAttr(), "Obj6b/test2 = Obj6/test3", "Moving Obj6b/test2 (with value value2) ...\nMoved Obj6b.test2")
self.call(building.CmdCpAttr(), "Obj6/test1 = Obj6b/test3", "Copying Obj6/test1 (with value value1) ...\nCopied Obj6.test1")
self.call(building.CmdName(), "Obj6b=Obj6c", "Object's name changed to 'Obj6c'.")
self.call(building.CmdDesc(), "Obj6c=TestDesc", "The description was set on Obj6c.")
self.call(building.CmdWipe(), "Obj6c/test2/test3", "Wiped attributes test2,test3 on Obj6c.")
self.call(building.CmdDestroy(), "TestObj1","TestObj1 was destroyed.")
self.call(building.CmdDig(), "TestRoom1=testroom;tr,back;b", "Created room TestRoom1")
self.call(building.CmdTunnel(), "n = TestRoom2;test2", "Created room TestRoom2")
self.call(building.CmdOpen(), "TestExit1=Room6b", "Created new Exit 'TestExit1' from Room6 to Room6b")
self.call(building.CmdLink(),"TestExit1 = TestRoom1","Link created TestExit1 > TestRoom1 (one way).")
self.call(building.CmdUnLink(), "TestExit1", "Former exit TestExit1 no longer links anywhere.")
self.call(building.CmdSetHome(), "Obj6 = Room6b", "Obj6's home location was changed from Room6")
self.call(building.CmdListCmdSets(), "", "<DefaultCharacter (Union, prio 0, perm)>:")
self.call(building.CmdTypeclass(), "Obj6 = src.objects.objects.Character", "Obj6's changed typeclass from src.objects.objects.Object to")
self.call(building.CmdLock(), "Obj6 = test:perm(Immortals)", "Added lock 'test:perm(Immortals)' to Obj6.")
self.call(building.CmdExamine(), "Obj6", "Name/key: Obj6")
self.call(building.CmdFind(), "TestRoom1", "One Match")
self.call(building.CmdScript(), "Obj6 = src.scripts.scripts.Script", "Script src.scripts.scripts.Script successfully added")
self.call(building.CmdTeleport(), "TestRoom1", "TestRoom1\nExits: back|Teleported to TestRoom1.")
from src.commands.default import comms
class TestComms(CommandTest):
CID = 7
def test_cmds(self):
# not testing the irc/imc2/rss commands here since testing happens offline
self.call(comms.CmdChannelCreate(), "testchan;test=Test Channel", "Created channel testchan and connected to it.")
self.call(comms.CmdAddCom(), "tc = testchan", "You are already connected to channel testchan. You can now")
self.call(comms.CmdDelCom(), "tc", "Your alias 'tc' for channel testchan was cleared.")
self.call(comms.CmdChannels(), "" ,"Available channels (use comlist,addcom and delcom to manage")
self.call(comms.CmdAllCom(), "", "Available channels (use comlist,addcom and delcom to manage")
self.call(comms.CmdCset(), "testchan=send:all()", "Lock(s) applied. Current locks on testchan:")
self.call(comms.CmdCdesc(), "testchan = Test Channel", "Description of channel 'testchan' set to 'Test Channel'.")
self.call(comms.CmdCemit(), "testchan = Test Message", "Sent to channel testchan: [testchan] Test Message")
self.call(comms.CmdCWho(), "testchan", "Channel subscriptions\ntestchan:\n TestPlayer7")
self.call(comms.CmdPage(), "TestPlayer7b = Test", "You paged TestPlayer7b with: 'Test'.")
self.call(comms.CmdCBoot(), "", "Usage: @cboot[/quiet] <channel> = <player> [:reason]") # noone else connected to boot
self.call(comms.CmdCdestroy(), "testchan" ,"Channel 'testchan' (Test Channel) was destroyed.")
## print all feedback from test commands (can become very verbose!)
#VERBOSE = True
#NOMANGLE = True # mangle command input for extra testing
#
#def cleanup():
# User.objects.all().delete()
# PlayerDB.objects.all().delete()
# ObjectDB.objects.all().delete()
# Channel.objects.all().delete()
# Msg.objects.all().delete()
# PlayerChannelConnection.objects.all().delete()
# ExternalChannelConnection.objects.all().delete()
# ServerConfig.objects.all().delete()
#
#class FakeSessionHandler(sessionhandler.ServerSessionHandler):
# """
# Fake sessionhandler, without an amp connection
# """
# def portal_shutdown(self):
# pass
# def disconnect(self, session, reason=""):
# pass
# def login(self, session):
# pass
# def session_sync(self):
# pass
# def data_out(self, session, string="", data=""):
# return string
#
#SESSIONS = FakeSessionHandler()
#
#class FakeSession(serversession.ServerSession):
# """
# A fake session that
# implements dummy versions of the real thing; this is needed to
# mimic a logged-in player.
# """
# protocol_key = "TestProtocol"
# 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',
# 'conn_time':time.time(), 'cmd_last':time.time(), 'cmd_last_visible':time.time(), 'cmd_total':1}
#
# def connectionMade(self):
# self.load_sync_data(self.sessdict)
# self.sessionhandler = SESSIONS
# def disconnectClient(self):
# pass
# def lineReceived(self, raw_string):
# pass
# def msg(self, message, data=None):
# global VERBOSE
# if message.startswith("Traceback (most recent call last):"):
# #retval = "Traceback last line: %s" % message.split('\n')[-4:]
# raise AssertionError(message)
# if self.player.character.ndb.return_string != None:
# return_list = self.player.character.ndb.return_string
# if hasattr(return_list, '__iter__'):
# rstring = return_list.pop(0)
# self.player.character.ndb.return_string = return_list
# else:
# rstring = return_list
# self.player.character.ndb.return_string = None
# message_noansi = ansi.parse_ansi(message, strip_ansi=True).strip()
# rstring = rstring.strip()
# if not message_noansi.startswith(rstring):
# sep1 = "\n" + "="*30 + "Wanted message" + "="*34 + "\n"
# sep2 = "\n" + "="*30 + "Returned message" + "="*32 + "\n"
# sep3 = "\n" + "="*78
# retval = sep1 + rstring + sep2 + message_noansi + sep3
# raise AssertionError(retval)
# if VERBOSE:
# print message
## setting up objects
#
#class CommandTest(TestCase):
# """
# Sets up the basics of testing the default commands and the generic things
# that should always be present in a command.
#
# Inherit new tests from this.
# """
#
# def setUp(self):
# "sets up the testing environment"
# #ServerConfig.objects.conf("default_home", 2)
# self.addCleanup(cleanup)
# self.room1 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room1")
# self.room2 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room2")
# # create a faux player/character for testing.
# self.char1 = create.create_player("TestChar", "testplayer@test.com", "testpassword", character_location=self.room1)
# self.char1.player.user.is_superuser = True
# self.char1.lock_storage = ""
# self.char1.locks = LockHandler(self.char1)
# self.char1.ndb.return_string = None
# self.sess1 = FakeSession()
# self.sess1.connectionMade()
# self.sess1.session_login(self.char1.player)
# # create second player
# self.char2 = create.create_player("TestChar2", "testplayer2@test.com", "testpassword2", character_location=self.room1)
# self.char2.player.user.is_superuser = False
# self.char2.lock_storage = ""
# self.char2.locks = LockHandler(self.char2)
# self.char2.ndb.return_string = None
# self.sess2 = FakeSession()
# self.sess2.connectionMade()
# self.sess2.session_login(self.char2.player)
# # A non-player-controlled character
# self.char3 = create.create_object(settings.BASE_CHARACTER_TYPECLASS, key="TestChar3", location=self.room1)
# # create some objects
# 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.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)
#
# def get_cmd(self, cmd_class, argument_string=""):
# """
# Obtain a cmd instance from a class and an input string
# Note: This does not make use of the cmdhandler functionality.
# """
# cmd = cmd_class()
# cmd.caller = self.char1
# cmd.cmdstring = cmd_class.key
# cmd.args = argument_string
# cmd.cmdset = None
# cmd.obj = self.char1
# return cmd
#
# def execute_cmd(self, raw_string, wanted_return_string=None, nomangle=False):
# """
# Creates the command through faking a normal command call;
# This also mangles the input in various ways to test if the command
# will be fooled.
# """
# if not nomangle and not VERBOSE and not NOMANGLE:
# # only mangle if not VERBOSE, to make fewer return lines
# test1 = re.sub(r'\s', '', raw_string) # remove all whitespace inside it
# test2 = "%s/åäö öäö;-:$£@*~^' 'test" % raw_string # inserting weird characters in call
# test3 = "%s %s" % (raw_string, raw_string) # multiple calls
# self.char1.execute_cmd(test1)
# self.char1.execute_cmd(test2)
# self.char1.execute_cmd(test3)
# # actual call, we potentially check so return is ok.
# self.char1.ndb.return_string = wanted_return_string
# try:
# self.char1.execute_cmd(raw_string)
# except AssertionError, e:
# self.fail(e)
# self.char1.ndb.return_string = None
#
#class BuildTest(CommandTest):
# """
# We need to turn of mangling for build commands since
# it creates arbitrary objects that mess up tests later.
# """
# NOMANGLE = True
#
#
##------------------------------------------------------------
## Default set Command testing
##------------------------------------------------------------
#
## # general.py tests
#
#class TestLook(CommandTest):
# def test_call(self):
# self.execute_cmd("look here")
#class TestHome(CommandTest):
# def test_call(self):
# self.char1.location = self.room1
# self.char1.home = self.room2
# self.execute_cmd("home")
# self.assertEqual(self.char1.location, self.room2)
#class TestPassword(CommandTest):
# def test_call(self):
# self.execute_cmd("@password testpassword = newpassword")
#class TestInventory(CommandTest):
# def test_call(self):
# self.execute_cmd("inv")
#class TestQuit(CommandTest):
# def test_call(self):
# self.execute_cmd("@quit")
#class TestPose(CommandTest):
# def test_call(self):
# self.execute_cmd("pose is testing","TestChar is testing")
#class TestNick(CommandTest):
# def test_call(self):
# self.char1.player.user.is_superuser = False
# self.execute_cmd("nickname testalias = testaliasedstring1")
# self.execute_cmd("nickname/player testalias = testaliasedstring2")
# self.execute_cmd("nickname/object testalias = testaliasedstring3")
# self.assertEqual(u"testaliasedstring1", self.char1.nicks.get("testalias"))
# self.assertEqual(u"testaliasedstring2", self.char1.nicks.get("testalias",nick_type="player"))
# self.assertEqual(u"testaliasedstring3", self.char1.nicks.get("testalias",nick_type="object"))
#class TestGet(CommandTest):
# def test_call(self):
# self.obj1.location = self.room1
# self.execute_cmd("get obj1", "You pick up obj1.")
#class TestDrop(CommandTest):
# def test_call(self):
# self.obj1.location = self.char1
# self.execute_cmd("drop obj1", "You drop obj1.")
#class TestWho(CommandTest):
# def test_call(self):
# self.execute_cmd("who")
#class TestSay(CommandTest):
# def test_call(self):
# self.execute_cmd("say Hello", 'You say, "Hello')
#class TestAccess(CommandTest):
# def test_call(self):
# self.execute_cmd("access")
#class TestEncoding(CommandTest):
# def test_call(self):
# global NOMANGLE
# NOMANGLE = True
# self.char1.db.encoding="utf-8"
# self.execute_cmd("@encoding", "Default encoding:")
# NOMANGLE = False
#
## help.py command tests
#
#class TestHelpSystem(CommandTest):
# def test_call(self):
# self.NOMANGLE = True
# sep = "-"*78 + "\n"
# 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/merge TestTopic = Test2", "Added the new text right after")
# self.execute_cmd("help TestTopic", sep + "Help topic for Testtopic\nTest1 Test2")
# self.execute_cmd("@help/append TestTopic = Test3", "Added the new text as a")
# self.execute_cmd("help TestTopic",sep + "Help topic for Testtopic\nTest1 Test2\n\nTest3")
# self.execute_cmd("@help/delete TestTopic","Deleted the help entry")
# self.execute_cmd("help TestTopic","No help entry found for 'TestTopic'")
#
## system.py command tests
#class TestPy(CommandTest):
# def test_call(self):
# self.execute_cmd("@py 1+2", [">>> 1+2", "<<< 3"])
#class TestScripts(CommandTest):
# def test_call(self):
# script = create.create_script(None, "test")
# self.execute_cmd("@scripts", "id")
#class TestObjects(CommandTest):
# def test_call(self):
# self.execute_cmd("@objects", "Database totals")
## Cannot be tested since we don't have an active server running at this point.
## class TestListService(CommandTest):
## def test_call(self):
## self.execute_cmd("@service/list", "---")
#class TestVersion(CommandTest):
# def test_call(self):
# self.execute_cmd("@version", '---')
#class TestTime(CommandTest):
# def test_call(self):
# self.execute_cmd("@time", "Current server uptime")
#class TestServerLoad(CommandTest):
# def test_call(self):
# self.execute_cmd("@serverload", "Server load")
#class TestPs(CommandTest):
# def test_call(self):
# self.execute_cmd("@ps","Non-timed scripts")
#
## admin.py command tests
#
#class TestBoot(CommandTest):
# def test_call(self):
# self.execute_cmd("@boot TestChar2","You booted TestChar2.")
#class TestDelPlayer(CommandTest):
# def test_call(self):
# self.execute_cmd("@delplayer TestChar2","Booting and informing player ...")
#class TestEmit(CommandTest):
# def test_call(self):
# self.execute_cmd("@emit Test message", "Emitted to room1.")
#class TestUserPassword(CommandTest):
# def test_call(self):
# self.execute_cmd("@userpassword TestChar2 = newpass", "TestChar2 - new password set to 'newpass'.")
#class TestPerm(CommandTest):
# def test_call(self):
# self.execute_cmd("@perm TestChar2 = Builders", "Permission 'Builders' given to")
## cannot test this here; screws up the test suite
##class TestPuppet(CommandTest):
## def test_call(self):
## self.execute_cmd("@puppet TestChar3", "You now control TestChar3.")
## self.execute_cmd("@puppet TestChar", "You now control TestChar.")
#class TestWall(CommandTest):
# def test_call(self):
# self.execute_cmd("@wall = This is a test message", "TestChar shouts")
#
#
## building.py command tests
#
#class TestObjAlias(BuildTest):
# def test_call(self):
# self.execute_cmd("@alias obj1 = obj1alias, obj1alias2", "Aliases for")
# self.execute_cmd("look obj1alias2", "obj1")
#class TestCopy(BuildTest):
# def test_call(self):
# self.execute_cmd("@copy obj1 = obj1_copy;alias1;alias2", "Copied obj1 to 'obj1_copy'")
# self.execute_cmd("look alias2","obj1_copy")
#class TestSet(BuildTest):
# def test_call(self):
# self.execute_cmd("@set obj1/test = value", "Created attribute obj1/test = value")
# self.execute_cmd("@set obj1/test", "Attribute obj1/test = value")
# self.assertEqual(self.obj1.db.test, u"value")
#class TestCpAttr(BuildTest):
# def test_call(self):
# self.execute_cmd("@set obj1/test = value")
# self.execute_cmd("@set obj2/test2 = value2")
# #self.execute_cmd("@cpattr obj1/test = obj2/test") # can't be tested since instances changes
# #self.assertEqual(self.obj2.db.test, u"value")
#class TestMvAttr(BuildTest):
# def test_call(self):
# self.execute_cmd("@set obj1/test = value")
# self.execute_cmd("@mvattr obj1/test = obj2")
# #self.assertEqual(self.obj2.db.test, u"value")
# #self.assertEqual(self.obj1.db.test, None)
#class TestCreate(BuildTest):
# def test_call(self):
# self.execute_cmd("@create testobj;alias1;alias2")
# self.execute_cmd("look alias1", "testobj")
#class TestDebug(BuildTest):
# def test_call(self):
# self.execute_cmd("@debug/obj obj1")
#class TestDesc(BuildTest):
# def test_call(self):
# self.execute_cmd("@desc obj1 = Test object", "The description was set on")
# #self.assertEqual(self.obj1.db.desc, u"Test object")
#class TestDestroy(BuildTest):
# def test_call(self):
# self.execute_cmd("@destroy obj1, obj2", "obj1 was destroyed.\nobj2 was destroyed.")
#class TestFind(BuildTest):
# def test_call(self):
# self.execute_cmd("@find obj1", "One Match")
#class TestDig(BuildTest):
# def test_call(self):
# self.execute_cmd("@dig room3;roomalias1;roomalias2 = north;n,south;s")
# self.execute_cmd("@find room3", "One Match")
# self.execute_cmd("@find roomalias1", "One Match")
# self.execute_cmd("@find roomalias2", "One Match")
# self.execute_cmd("@find/room roomalias2", "One Match")
# self.execute_cmd("@find/exit south", "One Match")
# self.execute_cmd("@find/exit n", "One Match")
#class TestUnLink(BuildTest):
# def test_call(self):
# self.execute_cmd("@dig room3;roomalias1, north, south")
# self.execute_cmd("@unlink north")
#class TestLink(BuildTest):
# def test_call(self):
# self.execute_cmd("@dig room3;roomalias1, north, south")
# self.execute_cmd("@unlink north")
# self.execute_cmd("@link north = room3")
#class TestHome(BuildTest):
# def test_call(self):
# self.obj1.db_home = self.obj2.dbobj
# self.obj1.save()
# self.execute_cmd("@home obj1")
# self.assertEqual(self.obj1.db_home, self.obj2.dbobj)
#class TestCmdSets(BuildTest):
# def test_call(self):
# self.execute_cmd("@cmdsets")
# self.execute_cmd("@cmdsets obj1")
#class TestName(BuildTest):
# def test_call(self):
# self.execute_cmd("@name obj1 = Test object", "Object's name changed to 'Test object'.")
# #self.assertEqual(self.obj1.key, u"Test object")
#class TestOpen(BuildTest):
# def test_call(self):
# self.execute_cmd("@dig room4;roomalias4")
# self.execute_cmd("@open testexit4;aliasexit4 = roomalias4", "Created new Exit")
#class TestTypeclass(BuildTest):
# def test_call(self):
# self.execute_cmd("@typeclass obj1 = src.objects.objects.Character", "obj's type is now")
# #self.assertEqual(self.obj1.db_typeclass_path, u"src.objects.objects.Character")
#class TestSet(BuildTest):
# def test_call(self):
# self.execute_cmd("@set box1/test = value")
# self.execute_cmd("@wipe box1", "Wiped")
# self.assertEqual(self.obj1.db.all, [])
#class TestLock(BuildTest):
# # lock functionality itseld is tested separately
# def test_call(self):
# self.char1.permissions = ["TestPerm"]
# self.execute_cmd("@lock obj1 = test:perm(TestPerm)")
# #self.assertEqual(True, self.obj1.access(self.char1, u"test"))
#class TestExamine(BuildTest):
# def test_call(self):
# self.execute_cmd("examine obj1", "------------")
#class TestTeleport(BuildTest):
# def test_call(self):
# self.execute_cmd("@tel obj1 = room1")
# self.assertEqual(self.obj1.location.key, self.room1.key)
#class TestScript(BuildTest):
# def test_call(self):
# self.execute_cmd("@script TestChar = examples.bodyfunctions.BodyFunctions", "Script successfully added")
#
## Comms commands
#
#class TestChannelCreate(CommandTest):
# def test_call(self):
# self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
# self.execute_cmd("testchan1 Hello", "[testchannel1] TestChar: Hello")
#class TestAddCom(CommandTest):
# def test_call(self):
# self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'")
# self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
# self.execute_cmd("addcom chan1 = testchannel1")
# self.execute_cmd("addcom chan2 = testchan1")
# self.execute_cmd("delcom testchannel1")
# self.execute_cmd("addcom testchannel1" "You now listen to the channel channel.")
#class TestDelCom(CommandTest):
# def test_call(self):
# self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'")
# self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
# self.execute_cmd("addcom chan1 = testchan1")
# self.execute_cmd("addcom chan2 = testchan1b")
# self.execute_cmd("addcom chan3 = testchannel1")
# self.execute_cmd("delcom chan1", "Your alias 'chan1' for ")
# self.execute_cmd("delcom chan2", "Your alias 'chan2' for ")
# self.execute_cmd("delcom testchannel1" "You stop listening to")
#class TestAllCom(CommandTest):
# 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("allcom off")
# self.execute_cmd("allcom on")
# self.execute_cmd("allcom destroy")
#class TestChannels(CommandTest):
# def test_call(self):
# self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
# self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'")
#class TestCBoot(CommandTest):
# def test_call(self):
# self.execute_cmd("@cdestroy testchannel1", "Channel 'testchannel1'")
# self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
# self.execute_cmd("addcom testchan = testchannel1")
# self.execute_cmd("@cboot testchannel1 = TestChar", "TestChar boots TestChar from channel.")
#class TestCemit(CommandTest):
# def test_call(self):
# self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
# self.execute_cmd("@cemit testchan1 = Testing!", "[testchannel1] Testing!")
#class TestCwho(CommandTest):
# def test_call(self):
# self.execute_cmd("@ccreate testchannel1;testchan1;testchan1b = This is a test channel")
# self.execute_cmd("@cwho testchan1b", "Channel subscriptions")
#
# OOC commands
#class TestOOC_and_IC(CommandTest): # can't be tested it seems, causes errors in other commands (?)
# def test_call(self):
# self.execute_cmd("@ooc", "\nYou go OOC.")
# self.execute_cmd("@ic", "\nYou become TestChar")
# Unloggedin commands
# these cannot be tested from here.
from src.commands.default import batchprocess
class TestBatchProcess(CommandTest):
CID = 8
def test_cmds(self):
# cannot test batchcode here, it must run inside the server process
self.player.ndb.is_superuser = True
self.call(batchprocess.CmdBatchCommands(), "examples.batch_cmds", "Running Batchcommand processor Automatic mode for examples.batch_cmds")
#self.call(batchprocess.CmdBatchCode(), "examples.batch_code", "")

View file

@ -610,6 +610,7 @@ class Channel(SharedMemoryModel):
"Connect the user to this channel"
if not self.access(player, 'listen'):
return False
player = player.dbobj
conn = PlayerChannelConnection.objects.create_connection(player, self)
if conn:
return True

View file

@ -308,7 +308,7 @@ class ObjectManager(TypedObjectManager):
#
def copy_object(self, original_object, new_key=None,
new_location=None, new_player=None, new_home=None,
new_location=None, new_home=None,
new_permissions=None, new_locks=None, new_aliases=None, new_destination=None):
"""
Create and return a new object as a copy of the original object. All will
@ -331,8 +331,6 @@ class ObjectManager(TypedObjectManager):
new_location = original_object.location
if not new_home:
new_home = original_object.home
if not new_player:
new_player = original_object.player
if not new_aliases:
new_aliases = original_object.aliases
if not new_locks:
@ -346,7 +344,7 @@ class ObjectManager(TypedObjectManager):
from src.utils import create
from src.scripts.models import ScriptDB
new_object = create.create_object(typeclass_path, key=new_key, location=new_location,
home=new_home, player=new_player, permissions=new_permissions,
home=new_home, permissions=new_permissions,
locks=new_locks, aliases=new_aliases, destination=new_destination)
if not new_object:
return None

View file

@ -419,6 +419,7 @@ class Object(TypeClass):
"delete:perm(Wizards)", # delete object
"get:all()", # pick up object
"call:true()", # allow to call commands on this object
"tell:perm(Wizards)", # allow emits to this object
"puppet:id(%s) or perm(Immortals) or pperm(Immortals)" % dbref])) # restricts puppeting of this object
def basetype_posthook_setup(self):