mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
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:
commit
f6ffd1b889
1 changed files with 16 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue