Merge pull request #5 from avalonhope/avalonhope-patch-search-object-attribute

Add unit test for seaching for objects by attribute
This commit is contained in:
Avalon Hope 2022-12-02 15:13:51 +00:00 committed by GitHub
commit f6ffd1b889

View file

@ -2,6 +2,7 @@ from evennia import DefaultObject, DefaultRoom
from evennia.objects.models import ObjectDB
from evennia.scripts.scripts import DefaultScript
from evennia.utils.search import (
search_object_attribute,
search_script,
search_script_attribute,
search_script_tag,
@ -80,3 +81,18 @@ class TestSearch(EvenniaTest):
DefaultObject.create("test_obj_2")
with self.assertRaises(ImportError):
search_typeclass("not.a.typeclass")
def test_search_object_attribute(self):
"""Check that an object can be found by its attributes."""
object, errors = DefaultObject.create("an-object")
object.db.an_attribute = "some value"
found = search_object_attribute(key="an_attribute", value="some value")
self.assertEqual(len(found), 1, errors)
self.assertEqual(object.key, found[0].key, errors)
def test_search_object_attribute_wrong(self):
"""Check that an object cannot be found by wrong value of its attributes."""
object, errors = DefaultObject.create("an-object")
object.db.an_attribute = "some value"
found = search_object_attribute(key="an_attribute", value="wrong value")
self.assertEqual(len(found), 0, errors)