Merge pull request #3013 from avalonhope/develop

Unit Tests for Searching Objects by Attribute
This commit is contained in:
Griatch 2022-12-02 19:57:00 +01:00 committed by GitHub
commit 01fbbafbd1

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)