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
|
|
@ -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