mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
feat: tests for add/remove attributes from monitorhandler
This commit is contained in:
parent
25e6fd9a3b
commit
17f7c0750b
1 changed files with 20 additions and 4 deletions
|
|
@ -13,6 +13,7 @@ from evennia.scripts.monitorhandler import MonitorHandler
|
|||
import inspect
|
||||
from evennia.scripts.manager import ScriptDBManager
|
||||
from collections import defaultdict
|
||||
from evennia.utils.dbserialize import dbserialize
|
||||
|
||||
class TestScript(BaseEvenniaTest):
|
||||
def test_create(self):
|
||||
|
|
@ -218,11 +219,26 @@ class TestMonitorHandler(TestCase):
|
|||
self.assertNotIn(obj, self.handler.monitors)
|
||||
self.assertEquals(defaultdict(lambda: defaultdict(dict)), self.handler.monitors)
|
||||
|
||||
def test_add_remove_attribute(self):
|
||||
"""Tests that adding and removing an object attribute to the monitor handler works correctly"""
|
||||
obj = mock.Mock()
|
||||
obj.name = "testaddattribute"
|
||||
fieldname = "name"
|
||||
callback = dummy_func
|
||||
idstring = "test"
|
||||
category = "testattribute"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""Add attribute to handler and assert that it has been added"""
|
||||
self.handler.add(obj, fieldname, callback, idstring=idstring,category=category)
|
||||
|
||||
index = obj.attributes.get(fieldname, return_obj=True)
|
||||
name = "db_value[testattribute]"
|
||||
|
||||
self.assertIn(name, self.handler.monitors[index])
|
||||
self.assertIn(idstring, self.handler.monitors[index][name])
|
||||
self.assertEqual(self.handler.monitors[index][name][idstring], (callback, False, {}))
|
||||
|
||||
"""Remove attribute from the handler and assert that it is gone"""
|
||||
self.handler.remove(obj,fieldname,idstring=idstring,category=category)
|
||||
self.assertEquals(self.handler.monitors[index][name], {})
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue