Resolve merge conflicts

This commit is contained in:
Griatch 2020-07-18 23:30:23 +02:00
commit 90e149dc27
14 changed files with 214 additions and 63 deletions

View file

@ -1094,13 +1094,13 @@ class AttributeHandler:
repeat-calling add when having many Attributes to add.
Args:
*args (tuple): Tuples of varying length representing the
Attribute to add to this object. Supported tuples are
- (key, value)
- (key, value, category)
- (key, value, category, lockstring)
- (key, value, category, lockstring, default_access)
*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)`
- `(key, value, category, lockstring, default_access)`
Keyword args:
strattr (bool): If `True`, value must be a string. This

View file

@ -36,7 +36,7 @@ class Tag(models.Model):
indexed for efficient lookup in the database. Tags are shared
between objects - a new tag is only created if the key+category
combination did not previously exist, making them unsuitable for
storing object-related data (for this a full tag should be
storing object-related data (for this a regular Attribute should be
used).
The 'db_data' field is intended as a documentation field for the
@ -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,

View file

@ -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):
@ -123,3 +134,16 @@ class TestTypedObjectManager(EvenniaTest):
self._manager("get_by_tag", ["tagA", "tagB"], ["categoryA", "categoryB"], match="any"),
[],
)
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")