mirror of
https://github.com/evennia/evennia.git
synced 2026-03-24 00:36:30 +01:00
Unittest manager get_object_with_account
This commit is contained in:
parent
0f7d29783e
commit
f3fa6bad07
2 changed files with 28 additions and 9 deletions
|
|
@ -69,7 +69,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
object candidates.
|
||||
|
||||
Return:
|
||||
match (Object or list): One or more matching results.
|
||||
match (query): Matching query.
|
||||
|
||||
"""
|
||||
ostring = to_unicode(ostring).lstrip('*')
|
||||
|
|
@ -77,7 +77,7 @@ class ObjectDBManager(TypedObjectManager):
|
|||
dbref = self.dbref(ostring)
|
||||
if dbref:
|
||||
try:
|
||||
return self.get(id=dbref)
|
||||
return self.get(db_account__id=dbref)
|
||||
except self.model.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
|
@ -87,13 +87,13 @@ class ObjectDBManager(TypedObjectManager):
|
|||
if exact:
|
||||
return self.filter(cand_restriction & Q(db_account__username__iexact=ostring))
|
||||
else: # fuzzy matching
|
||||
ply_cands = self.filter(cand_restriction & Q(accountdb__username__istartswith=ostring)
|
||||
).values_list("db_key", flat=True)
|
||||
if candidates:
|
||||
index_matches = string_partial_matching(ply_cands, ostring, ret_index=True)
|
||||
return [obj for ind, obj in enumerate(make_iter(candidates)) if ind in index_matches]
|
||||
else:
|
||||
return string_partial_matching(ply_cands, ostring, ret_index=False)
|
||||
obj_cands = self.select_related().filter(cand_restriction & Q(db_account__username__istartswith=ostring))
|
||||
acct_cands = [obj.account for obj in obj_cands]
|
||||
|
||||
if obj_cands:
|
||||
index_matches = string_partial_matching([acct.key for acct in acct_cands], ostring, ret_index=True)
|
||||
acct_cands = [acct_cands[i].id for i in index_matches]
|
||||
return obj_cands.filter(db_account__id__in=acct_cands)
|
||||
|
||||
def get_objs_with_key_and_typeclass(self, oname, otypeclass_path, candidates=None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from evennia.utils.test_resources import EvenniaTest
|
||||
from evennia import DefaultObject, DefaultCharacter, DefaultRoom, DefaultExit
|
||||
from evennia.objects.models import ObjectDB
|
||||
|
||||
|
||||
class DefaultObjectTest(EvenniaTest):
|
||||
|
|
@ -45,3 +46,21 @@ class DefaultObjectTest(EvenniaTest):
|
|||
|
||||
self.assertTrue(self.room1.get_absolute_url())
|
||||
self.assertTrue('admin' in self.room1.web_get_admin_url())
|
||||
|
||||
|
||||
class TestObjectManager(EvenniaTest):
|
||||
"Test object manager methods"
|
||||
def test_get_object_with_account(self):
|
||||
query = ObjectDB.objects.get_object_with_account("TestAccount").first()
|
||||
self.assertEqual(query, self.char1)
|
||||
query = ObjectDB.objects.get_object_with_account(self.account.dbref)
|
||||
self.assertEqual(query, self.char1)
|
||||
query = ObjectDB.objects.get_object_with_account("TestAccou").first()
|
||||
self.assertEqual(query, None)
|
||||
|
||||
query = ObjectDB.objects.get_object_with_account("TestAccou", exact=False)
|
||||
self.assertEqual(tuple(query), (self.char1, self.char2))
|
||||
|
||||
query = ObjectDB.objects.get_object_with_account(
|
||||
"TestAccou", candidates=[self.char1, self.obj1], exact=False)
|
||||
self.assertEqual(list(query), [self.char1])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue