Add unit tests to all menu helpers

This commit is contained in:
Griatch 2018-07-04 19:25:44 +02:00
parent ec9813c256
commit 706ed47ccc
3 changed files with 16 additions and 12 deletions

View file

@ -825,10 +825,11 @@ def _update_spawned(caller, **kwargs):
"""update existing objects"""
prototype = kwargs['prototype']
objects = kwargs['objects']
back_node = kwargs['back_key']
num_changed = spawner.batch_update_objects_with_prototype(prototype, objects=objects)
back_node = kwargs['back_node']
diff = kwargs.get('diff', None)
num_changed = spawner.batch_update_objects_with_prototype(prototype, diff=diff, objects=objects)
caller.msg("|g{num} objects were updated successfully.|n".format(num=num_changed))
return back_key
return back_node
def _keep_diff(caller, **kwargs):
@ -884,15 +885,15 @@ def node_update_objects(caller, **kwargs):
text.append(line.format(iopt=io, key=key, old=old_val,
sep=" |y->|n ", new=new_val, change=inst))
options.append(_keep_option(key, prototype,
obj, obj_prototype, diff, objects, back_node))
obj, obj_prototype, diff, update_objects, back_node))
elif inst == "REMOVE":
text.append(line.format(iopt=io, key=key, old=old_val,
sep=" |r->|n ", new='', change=inst))
options.append(_keep_option(key, prototype,
obj, obj_prototype, diff, objects, back_node))
obj, obj_prototype, diff, update_objects, back_node))
options.extend(
[{"key": ("|wu|r update {} objects".format(len(update_objects)), "update", "u"),
"goto": (_update_spawned, {"prototype": prototype, "objects": objects,
"goto": (_update_spawned, {"prototype": prototype, "objects": update_objects,
"back_node": back_node, "diff": diff})},
{"key": ("|wr|neset changes", "reset", "r"),
"goto": ("node_update_objects", {"prototype": prototype, "back_node": back_node,
@ -1111,7 +1112,7 @@ def start_olc(caller, session=None, prototype=None):
"node_location": node_location,
"node_home": node_home,
"node_destination": node_destination,
"node_update_objects": node_o
"node_update_objects": node_update_objects,
"node_prototype_desc": node_prototype_desc,
"node_prototype_tags": node_prototype_tags,
"node_prototype_locks": node_prototype_locks,

View file

@ -290,7 +290,7 @@ def batch_update_objects_with_prototype(prototype, diff=None, objects=None):
return 0
if not diff:
diff = prototype_diff_from_object(new_prototype, objects[0])
diff, _ = prototype_diff_from_object(new_prototype, objects[0])
changed = 0
for obj in objects:

View file

@ -446,13 +446,16 @@ class TestMenuModule(EvenniaTest):
self.assertEqual(obj.typeclass_path, "evennia.objects.objects.DefaultObject")
self.assertEqual(obj.tags.get(category=spawner._PROTOTYPE_TAG_CATEGORY), self.test_prot['prototype_key'])
self.assertEqual(olc_menus._update_spawned(caller, prototype=self.test_prot, objects=[obj]), 0) # no changes to apply
self.test_prot['key'] = "updated key" # change prototype
self.assertEqual(self._update_spawned(caller, prototype=self.test_prot, objects=[obj]), 1) # apply change to the one obj
# update helpers
self.assertEqual(olc_menus._update_spawned(
caller, prototype=self.test_prot, back_node="foo", objects=[obj]), 'foo') # no changes to apply
self.test_prot['key'] = "updated key" # change prototype
self.assertEqual(olc_menus._update_spawned(
caller, prototype=self.test_prot, objects=[obj], back_node='foo'), 'foo') # apply change to the one obj
# load helpers
self.assertEqual(olc_menus._prototype_load_select(caller, self.test_prot['prototype_key']), "node_index")