Add unittest for typeclass/prototype, some cleanup

This commit is contained in:
Griatch 2020-02-24 08:32:49 +01:00
parent ecd5cf2be7
commit a6940fca90
2 changed files with 25 additions and 8 deletions

View file

@ -1913,8 +1913,8 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS):
Usage:
typeclass[/switch] <object> [= typeclass.path]
type ''
parent ''
typeclass/prototype <object> = prototype_key
typeclass/list/show [typeclass.path]
swap - this is a shorthand for using /force/reset flags.
update - this is a shorthand for using the /force/reload flag.
@ -2110,15 +2110,11 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS):
prompt += "\n|yWARNING:|n Use the /reset switch to apply the prototype over a blank state."
prompt += "\nAre you sure you want to apply these changes [yes]/no?"
answer = yield (prompt)
answer = "yes" if answer == "" else answer
if answer and answer not in ("yes", "y", "no", "n"):
if answer and answer in ("no", "n"):
caller.msg(
"Canceled: Either accept the default by pressing return or specify yes/no."
"Canceled: No changes were applied."
)
return
elif answer.strip().lower() in ("n", "no"):
caller.msg("Canceled: No object was modified.")
return
# we let this raise exception if needed
obj.swap_typeclass(

View file

@ -991,6 +991,27 @@ class TestBuilding(CommandTest):
"All object creation hooks were run. All old attributes where deleted before the swap.",
)
from evennia.prototypes.prototypes import homogenize_prototype
test_prototype = [homogenize_prototype(
{"prototype_key": "testkey",
"prototype_tags": [],
"typeclass": "typeclasses.objects.Object",
"key":"replaced_obj",
"attrs": [("foo", "bar", None, ""),
("desc", "protdesc", None, "")]})]
with mock.patch("evennia.commands.default.building.protlib.search_prototype",
new=mock.MagicMock(return_value=test_prototype)) as mprot:
self.call(
building.CmdTypeclass(),
"/prototype Obj=testkey",
"replaced_obj changed typeclass from "
"evennia.objects.objects.DefaultObject to "
"typeclasses.objects.Object.\nAll object creation hooks were "
"run. Attributes set before swap were not removed. Prototype "
"'replaced_obj' was successfully applied over the object type."
)
assert self.obj1.db.desc == "protdesc"
def test_lock(self):
self.call(building.CmdLock(), "", "Usage: ")
self.call(building.CmdLock(), "Obj = test:all()", "Added lock 'test:all()' to Obj.")