Update test_search.py

This commit is contained in:
Avalon Hope 2022-11-25 11:25:50 +00:00 committed by GitHub
parent f2239f07ca
commit dac38f258d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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."""
script, 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."""
script, errors = DefaultObject.create("an-object")
script.db.an_attribute = "some value"
found = search_object_attribute(key="an_attribute", value="wrong value")
self.assertEqual(len(found), 0, errors)