mirror of
https://github.com/evennia/evennia.git
synced 2026-03-20 14:56:30 +01:00
Add unittest for Attr/Tag.batch_add, clarify docstrings. Resolves #2125
This commit is contained in:
parent
08190a7ff4
commit
f615886d24
4 changed files with 32 additions and 5 deletions
|
|
@ -428,8 +428,10 @@ class DefaultChannel(ChannelDB, metaclass=TypeclassBase):
|
|||
msgobj = self.pre_send_message(msgobj)
|
||||
if not msgobj:
|
||||
return False
|
||||
if sender_strings:
|
||||
sender_strings = list(set(make_iter(sender_strings)))
|
||||
msgobj = self.message_transform(
|
||||
msgobj, emit=emit, sender_strings=list(set(sender_strings)), external=external
|
||||
msgobj, emit=emit, sender_strings=sender_strings, external=external
|
||||
)
|
||||
self.distribute_message(msgobj, online=online)
|
||||
self.post_send_message(msgobj)
|
||||
|
|
|
|||
|
|
@ -593,8 +593,9 @@ class AttributeHandler(object):
|
|||
repeat-calling add when having many Attributes to add.
|
||||
|
||||
Args:
|
||||
indata (list): List of tuples of varying length representing the
|
||||
Attribute to add to this object. Supported tuples are
|
||||
*args (tuple): Each argument should be a tuples (can be of varying
|
||||
length) representing the Attribute to add to this object.
|
||||
Supported tuples are
|
||||
- `(key, value)`
|
||||
- `(key, value, category)`
|
||||
- `(key, value, category, lockstring)`
|
||||
|
|
|
|||
|
|
@ -449,8 +449,8 @@ class TagHandler(object):
|
|||
Batch-add tags from a list of tuples.
|
||||
|
||||
Args:
|
||||
tuples (tuple or str): Any number of `tagstr` keys, `(keystr, category)` or
|
||||
`(keystr, category, data)` tuples.
|
||||
*args (tuple or str): Each argument should be a `tagstr` keys or tuple `(keystr, category)` or
|
||||
`(keystr, category, data)`. It's possible to mix input types.
|
||||
|
||||
Notes:
|
||||
This will generate a mimimal number of self.add calls,
|
||||
|
|
|
|||
|
|
@ -42,6 +42,17 @@ class TestAttributes(EvenniaTest):
|
|||
self.obj1.attributes.add(key, value)
|
||||
self.assertEqual(self.obj1.attributes.get(key), value)
|
||||
|
||||
def test_batch_add(self):
|
||||
attrs = [("key1", "value1"),
|
||||
("key2", "value2", "category2"),
|
||||
("key3", "value3"),
|
||||
("key4", "value4", "category4", "attrread:id(1)", False)]
|
||||
new_attrs = self.obj1.attributes.batch_add(*attrs)
|
||||
attrobj = self.obj1.attributes.get(key="key4", category="category4", return_obj=True)
|
||||
self.assertEqual(attrobj.value, "value4")
|
||||
self.assertEqual(attrobj.category, "category4")
|
||||
self.assertEqual(attrobj.locks.all(), ["attrread:id(1)"])
|
||||
|
||||
|
||||
class TestTypedObjectManager(EvenniaTest):
|
||||
def _manager(self, methodname, *args, **kwargs):
|
||||
|
|
@ -146,3 +157,16 @@ class TestTypedObjectManager(EvenniaTest):
|
|||
),
|
||||
[],
|
||||
)
|
||||
|
||||
def test_batch_add(self):
|
||||
tags = ["tag1",
|
||||
("tag2", "category2"),
|
||||
"tag3",
|
||||
("tag4", "category4", "data4")
|
||||
]
|
||||
self.obj1.tags.batch_add(*tags)
|
||||
self.assertEqual(self.obj1.tags.get("tag1"), "tag1")
|
||||
tagobj = self.obj1.tags.get("tag4", category="category4", return_tagobj=True)
|
||||
self.assertEqual(tagobj.db_key, "tag4")
|
||||
self.assertEqual(tagobj.db_category, "category4")
|
||||
self.assertEqual(tagobj.db_data, "data4")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue