mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Started to go through the unittest errors, fixing player creation.
This commit is contained in:
parent
0b01df1fcc
commit
1130dc5757
11 changed files with 58 additions and 60 deletions
|
|
@ -386,7 +386,7 @@ class CmdCBoot(MuxPlayerCommand):
|
|||
string = "You don't control this channel."
|
||||
self.msg(string)
|
||||
return
|
||||
if not player.dbobj in channel.db_subscriptions.all():
|
||||
if not player in channel.db_subscriptions.all():
|
||||
string = "Player %s is not connected to channel %s." % (player.key, channel.key)
|
||||
self.msg(string)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -394,7 +394,7 @@ class CmdObjects(MuxCommand):
|
|||
latesttable.align = 'l'
|
||||
for obj in objs:
|
||||
latesttable.add_row(utils.datetime_format(obj.date_created),
|
||||
obj.dbref, obj.key, obj.typeclass.path)
|
||||
obj.dbref, obj.key, obj.path)
|
||||
|
||||
string = "\n{wObject subtype totals (out of %i Objects):{n\n%s" % (nobjs, totaltable)
|
||||
string += "\n{wObject typeclass distribution:{n\n%s" % typetable
|
||||
|
|
@ -437,7 +437,7 @@ class CmdPlayers(MuxCommand):
|
|||
plyrs = PlayerDB.objects.all().order_by("db_date_created")[max(0, nplayers - nlim):]
|
||||
latesttable = EvTable("{wcreated{n", "{wdbref{n", "{wname{n", "{wtypeclass{n", border="cells", align="l")
|
||||
for ply in plyrs:
|
||||
latesttable.add_row(utils.datetime_format(ply.date_created), ply.dbref, ply.key, ply.typeclass.path)
|
||||
latesttable.add_row(utils.datetime_format(ply.date_created), ply.dbref, ply.key, ply.path)
|
||||
|
||||
string = "\n{wPlayer typeclass distribution:{n\n%s" % typetable
|
||||
string += "\n{wLast %s Players created:{n\n%s" % (min(nplayers, nlim), latesttable)
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ import re
|
|||
from django.conf import settings
|
||||
from django.utils.unittest import TestCase
|
||||
from src.server.serversession import ServerSession
|
||||
from src.objects.objects import Object, Character
|
||||
from src.players.player import Player
|
||||
from src.objects.objects import DefaultObject, DefaultCharacter
|
||||
from src.players.player import DefaultPlayer
|
||||
from src.utils import create, ansi
|
||||
from src.server.sessionhandler import SESSIONS
|
||||
|
||||
|
|
@ -41,13 +41,13 @@ SESSIONS.data_out = dummy
|
|||
SESSIONS.disconnect = dummy
|
||||
|
||||
|
||||
class TestObjectClass(Object):
|
||||
class TestObjectClass(DefaultObject):
|
||||
def msg(self, text="", **kwargs):
|
||||
"test message"
|
||||
pass
|
||||
|
||||
|
||||
class TestCharacterClass(Character):
|
||||
class TestCharacterClass(DefaultCharacter):
|
||||
def msg(self, text="", **kwargs):
|
||||
"test message"
|
||||
if self.player:
|
||||
|
|
@ -58,17 +58,18 @@ class TestCharacterClass(Character):
|
|||
self.ndb.stored_msg.append(text)
|
||||
|
||||
|
||||
class TestPlayerClass(Player):
|
||||
class TestPlayerClass(DefaultPlayer):
|
||||
def msg(self, text="", **kwargs):
|
||||
"test message"
|
||||
if not self.ndb.stored_msg:
|
||||
self.ndb.stored_msg = []
|
||||
self.ndb.stored_msg.append(text)
|
||||
|
||||
def _get_superuser(self):
|
||||
"test with superuser flag"
|
||||
return self.ndb.is_superuser
|
||||
is_superuser = property(_get_superuser)
|
||||
# not supported to overload is_superuser field with property.
|
||||
#def _get_superuser(self):
|
||||
# "test with superuser flag"
|
||||
# return self.ndb.is_superuser
|
||||
#is_superuser = property(_get_superuser)
|
||||
|
||||
|
||||
class CommandTest(TestCase):
|
||||
|
|
@ -81,10 +82,10 @@ class CommandTest(TestCase):
|
|||
#print "creating player %i: %s" % (self.CID, self.__class__.__name__)
|
||||
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.room1 = create.create_object("src.objects.objects.Room", key="Room%i"%self.CID, nohome=True)
|
||||
self.room1 = create.create_object("src.objects.objects.DefaultRoom", key="Room%i"%self.CID, nohome=True)
|
||||
self.room1.db.desc = "room_desc"
|
||||
settings.DEFAULT_HOME = "#%i" % self.room1.id # we must have a default home
|
||||
self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID)
|
||||
self.room2 = create.create_object("src.objects.objects.DefaultRoom", key="Room%ib" % self.CID)
|
||||
self.obj1 = create.create_object(TestObjectClass, key="Obj%i" % self.CID, location=self.room1, home=self.room1)
|
||||
self.obj2 = create.create_object(TestObjectClass, key="Obj%ib" % self.CID, location=self.room1, home=self.room1)
|
||||
self.char1 = create.create_object(TestCharacterClass, key="Char%i" % self.CID, location=self.room1, home=self.room1)
|
||||
|
|
|
|||
|
|
@ -30,20 +30,20 @@ class Channel(ChannelDB):
|
|||
# this is only set if the channel was created
|
||||
# with the utils.create.create_channel function.
|
||||
cdict = self._createdict
|
||||
if not cdict["key"]:
|
||||
if not cdict.get("key"):
|
||||
if not self.db_key:
|
||||
self.db_key = "#i" % self.dbid
|
||||
elif cdict["key"] and self.key != cdict["key"]:
|
||||
self.key = cdict["key"]
|
||||
if cdict["keep_log"]:
|
||||
if cdict.get("keep_log"):
|
||||
self.db_keep_log = cdict["keep_log"]
|
||||
if cdict["aliases"]:
|
||||
if cdict.get("aliases"):
|
||||
self.aliases.add(cdict["aliases"])
|
||||
if cdict["locks"]:
|
||||
if cdict.get("locks"):
|
||||
self.locks.add(cdict["locks"])
|
||||
if cdict["keep_log"]:
|
||||
if cdict.get("keep_log"):
|
||||
self.attributes.add("keep_log", cdict["keep_log"])
|
||||
if cdict["desc"]:
|
||||
if cdict.get("desc"):
|
||||
self.attributes.add("desc", cdict["desc"])
|
||||
|
||||
def at_channel_creation(self):
|
||||
|
|
@ -61,7 +61,6 @@ class Channel(ChannelDB):
|
|||
"""
|
||||
if hasattr(player, "player"):
|
||||
player = player.player
|
||||
player = player.dbobj
|
||||
return player in self.db_subscriptions.all()
|
||||
|
||||
def connect(self, player):
|
||||
|
|
@ -90,9 +89,9 @@ class Channel(ChannelDB):
|
|||
if not disconnect:
|
||||
return False
|
||||
# disconnect
|
||||
self.db_subscriptions.remove(player.dbobj)
|
||||
self.db_subscriptions.remove(player)
|
||||
# post-disconnect hook
|
||||
self.post_leave_channel(player.dbobj)
|
||||
self.post_leave_channel(player)
|
||||
return True
|
||||
|
||||
def access(self, accessing_obj, access_type='listen', default=False):
|
||||
|
|
|
|||
|
|
@ -283,11 +283,11 @@ class DefaultObject(ObjectDB):
|
|||
"""
|
||||
return any(self.sessions)
|
||||
|
||||
@property
|
||||
def is_superuser(self):
|
||||
"Check if user has a player, and if so, if it is a superuser."
|
||||
return self.db_player and self.db_player.is_superuser \
|
||||
and not self.db_player.attributes.get("_quell")
|
||||
#@property
|
||||
#def is_superuser(self):
|
||||
# "Check if user has a player, and if so, if it is a superuser."
|
||||
# return self.db_player and self.db_player.is_superuser \
|
||||
# and not self.db_player.attributes.get("_quell")
|
||||
|
||||
def contents_get(self, exclude=None):
|
||||
"""
|
||||
|
|
@ -858,32 +858,32 @@ class DefaultObject(ObjectDB):
|
|||
# call's kwargs to override the values set by hooks.
|
||||
cdict = self._createdict
|
||||
updates = []
|
||||
if not cdict["key"]:
|
||||
if not cdict.get("key"):
|
||||
if not self.db_key:
|
||||
self.db_key = "#%i" % self.dbid
|
||||
updates.append("db_key")
|
||||
elif self.key != cdict["key"]:
|
||||
elif self.key != cdict.get("key"):
|
||||
updates.append("db_key")
|
||||
self.db_key = cdict["key"]
|
||||
if cdict["location"] and self.location != cdict["location"]:
|
||||
if cdict.get("location") and self.location != cdict["location"]:
|
||||
self.db_location = cdict["location"]
|
||||
updates.append("db_location")
|
||||
if cdict["home"] and self.home != cdict["home"]:
|
||||
if cdict.get("home") and self.home != cdict["home"]:
|
||||
self.home = cdict["home"]
|
||||
updates.append("db_home")
|
||||
if cdict["destination"] and self.destination != cdict["destination"]:
|
||||
if cdict.get("destination") and self.destination != cdict["destination"]:
|
||||
self.destination = cdict["destination"]
|
||||
updates.append("db_destination")
|
||||
if updates:
|
||||
self.save(update_fields=updates)
|
||||
|
||||
if cdict["permissions"]:
|
||||
if cdict.get("permissions"):
|
||||
self.permissions.add(cdict["permissions"])
|
||||
if cdict["locks"]:
|
||||
if cdict.get("locks"):
|
||||
self.locks.add(cdict["locks"])
|
||||
if cdict["aliases"]:
|
||||
if cdict.get("aliases"):
|
||||
self.aliases.add(cdict["aliases"])
|
||||
if cdict["location"]:
|
||||
if cdict.get("location"):
|
||||
cdict["location"].at_object_receive(self, None)
|
||||
self.at_after_move(None)
|
||||
del self._createdict
|
||||
|
|
|
|||
|
|
@ -93,10 +93,6 @@ class PlayerDB(TypedObject, AbstractUser):
|
|||
# Database manager
|
||||
objects = PlayerDBManager()
|
||||
|
||||
# caches for quick lookups
|
||||
_typeclass_paths = settings.PLAYER_TYPECLASS_PATHS
|
||||
_default_typeclass_path = settings.BASE_PLAYER_TYPECLASS or "src.players.player.Player"
|
||||
|
||||
class Meta:
|
||||
app_label = 'players'
|
||||
verbose_name = 'Player'
|
||||
|
|
|
|||
|
|
@ -535,9 +535,9 @@ class DefaultPlayer(PlayerDB):
|
|||
# this will only be set if the utils.create_player
|
||||
# function was used to create the object.
|
||||
cdict = self._createdict
|
||||
if "locks" in cdict:
|
||||
if cdict.get("locks"):
|
||||
self.locks.add(cdict["locks"])
|
||||
if "permissions" in cdict:
|
||||
if cdict.get("permissions"):
|
||||
permissions = cdict["permissions"]
|
||||
del self._createdict
|
||||
|
||||
|
|
|
|||
|
|
@ -443,28 +443,28 @@ class Script(ScriptBase):
|
|||
# set by hooks.
|
||||
cdict = self._createdict
|
||||
updates = []
|
||||
if not cdict["key"]:
|
||||
if not cdict.get("key"):
|
||||
if not self.db_key:
|
||||
self.db_key = "#%i" % self.dbid
|
||||
updates.append("db_key")
|
||||
elif self.db_key != cdict["db_key"]:
|
||||
elif self.db_key != cdict["key"]:
|
||||
self.db_key = cdict["key"]
|
||||
updates.append("db_key")
|
||||
if cdict["interval"] and self.interval != cdict["interval"]:
|
||||
if cdict.get("interval") and self.interval != cdict["interval"]:
|
||||
self.db_interval = cdict["interval"]
|
||||
updates.append("db_interval")
|
||||
if cdict["start_delay"] and self.start_delay != cdict["start_delay"]:
|
||||
if cdict.get("start_delay") and self.start_delay != cdict["start_delay"]:
|
||||
self.db_start_delay = cdict["start_delay"]
|
||||
updates.append("db_start_delay")
|
||||
if cdict["repeats"] and self.repeats != cdict["repeats"]:
|
||||
if cdict.get("repeats") and self.repeats != cdict["repeats"]:
|
||||
self.db_repeats = cdict["repeats"]
|
||||
updates.append("db_repeats")
|
||||
if cdict["persistent"] and self.persistent != cdict["persistent"]:
|
||||
if cdict.get("persistent") and self.persistent != cdict["persistent"]:
|
||||
self.db_persistent = cdict["persistent"]
|
||||
updates.append("db_persistent")
|
||||
if updates:
|
||||
self.save(update_fields=updates)
|
||||
if not cdict["autostart"]:
|
||||
if not cdict.get("autostart"):
|
||||
# don't auto-start the script
|
||||
return
|
||||
|
||||
|
|
|
|||
|
|
@ -325,6 +325,8 @@ class TypedObject(SharedMemoryModel):
|
|||
sure nothing in the new typeclass clashes
|
||||
with the old one. If you supply a list,
|
||||
only those named attributes will be cleared.
|
||||
run_start_hooks - trigger the start hooks of the object, as if
|
||||
it was created for the first time.
|
||||
no_default - if this is active, the swapper will not allow for
|
||||
swapping to a default typeclass in case the given
|
||||
one fails for some reason. Instead the old one
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ Models covered:
|
|||
"""
|
||||
from django.conf import settings
|
||||
from django.db import IntegrityError
|
||||
from django.utils import timezone
|
||||
from src.utils import logger
|
||||
from src.utils.utils import make_iter, class_from_module, dbid_to_obj
|
||||
|
||||
|
|
@ -348,7 +349,6 @@ def create_player(key, email, password,
|
|||
if isinstance(typeclass, basestring):
|
||||
# a path is given. Load the actual typeclass.
|
||||
typeclass = class_from_module(typeclass, settings.OBJECT_TYPECLASS_PATHS)
|
||||
typeclass_path = typeclass.path
|
||||
|
||||
# setup input for the create command. We use PlayerDB as baseclass
|
||||
# here to give us maximum freedom (the typeclasses will load
|
||||
|
|
@ -362,16 +362,16 @@ def create_player(key, email, password,
|
|||
# this handles a given dbref-relocate to a player.
|
||||
report_to = dbid_to_obj(report_to, _PlayerDB)
|
||||
|
||||
# create the correct player object
|
||||
if is_superuser:
|
||||
new_player = _PlayerDB.objects.create_superuser(key, email, password)
|
||||
else:
|
||||
new_player = _PlayerDB.objects.create_user(key, email, password)
|
||||
new_player.db_typeclass_path = typeclass_path
|
||||
# store the call signature for the signal
|
||||
# create the correct player entity, using the setup from
|
||||
# base django auth.
|
||||
now = timezone.now()
|
||||
email = typeclass.objects.normalize_email(email)
|
||||
new_player = typeclass(username=key, email=email,
|
||||
is_staff=is_superuser, is_superuser=is_superuser,
|
||||
last_login=now, date_joined=now)
|
||||
new_player.set_password(password)
|
||||
new_player._createdict = {"locks":locks, "permissions":permissions,
|
||||
"report_to":report_to}
|
||||
|
||||
# saving will trigger the signal that calls the
|
||||
# at_first_save hook on the typeclass, where the _createdict
|
||||
# can be used.
|
||||
|
|
|
|||
|
|
@ -187,8 +187,8 @@ class SharedMemoryModelBase(ModelBase):
|
|||
for fieldname, field in ((fname, field) for fname, field in attrs.items()
|
||||
if fname.startswith("db_") and type(field).__name__ != "ManyToManyField"):
|
||||
foreignkey = type(field).__name__ == "ForeignKey"
|
||||
#print fieldname, type(field).__name__, field
|
||||
wrappername = "dbid" if fieldname == "id" else fieldname.replace("db_", "", 1)
|
||||
#print fieldname, wrappername
|
||||
if wrappername not in attrs:
|
||||
# makes sure not to overload manually created wrappers on the model
|
||||
#print "wrapping %s -> %s" % (fieldname, wrappername)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue