Merge pull request #3013 from avalonhope/develop
Unit Tests for Searching Objects by Attribute
This commit is contained in:
commit
01fbbafbd1
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.objects.models import ObjectDB
|
||||||
from evennia.scripts.scripts import DefaultScript
|
from evennia.scripts.scripts import DefaultScript
|
||||||
from evennia.utils.search import (
|
from evennia.utils.search import (
|
||||||
|
search_object_attribute,
|
||||||
search_script,
|
search_script,
|
||||||
search_script_attribute,
|
search_script_attribute,
|
||||||
search_script_tag,
|
search_script_tag,
|
||||||
|
|
@ -80,3 +81,18 @@ class TestSearch(EvenniaTest):
|
||||||
DefaultObject.create("test_obj_2")
|
DefaultObject.create("test_obj_2")
|
||||||
with self.assertRaises(ImportError):
|
with self.assertRaises(ImportError):
|
||||||
search_typeclass("not.a.typeclass")
|
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