mirror of
https://github.com/evennia/evennia.git
synced 2026-03-31 04:57:16 +02:00
Fix an inconsistency in category-refresh for empty string, related to #2236
This commit is contained in:
parent
46ed479287
commit
057bed7010
3 changed files with 48 additions and 7 deletions
|
|
@ -181,10 +181,10 @@ class Attribute(SharedMemoryModel):
|
|||
#
|
||||
|
||||
def __str__(self):
|
||||
return smart_str("%s(%s)" % (self.db_key, self.id))
|
||||
return smart_str("%s[category=%s](#%s)" % (self.db_key, self.db_category, self.id))
|
||||
|
||||
def __repr__(self):
|
||||
return "%s(%s)" % (self.db_key, self.id)
|
||||
return "%s[category=%s](#%s)" % (self.db_key, self.db_category, self.id)
|
||||
|
||||
def access(self, accessing_obj, access_type="attrread", default=False, **kwargs):
|
||||
"""
|
||||
|
|
@ -257,7 +257,7 @@ class AttributeHandler(object):
|
|||
"%s-%s"
|
||||
% (
|
||||
to_str(attr.db_key).lower(),
|
||||
attr.db_category.lower() if attr.db_category else None,
|
||||
attr.db_category.lower() if attr.db_category is not None else None,
|
||||
),
|
||||
attr,
|
||||
)
|
||||
|
|
@ -289,7 +289,7 @@ class AttributeHandler(object):
|
|||
|
||||
"""
|
||||
key = key.strip().lower() if key else None
|
||||
category = category.strip().lower() if category else None
|
||||
category = category.strip().lower() if category is not None else None
|
||||
if key:
|
||||
cachekey = "%s-%s" % (key, category)
|
||||
cachefound = False
|
||||
|
|
@ -558,6 +558,7 @@ class AttributeHandler(object):
|
|||
return
|
||||
|
||||
category = category.strip().lower() if category is not None else None
|
||||
|
||||
keystr = key.strip().lower()
|
||||
attr_obj = self._getcache(key, category)
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ def create_object(
|
|||
location itself or during unittests.
|
||||
attributes (list): Tuples on the form (key, value) or (key, value, category),
|
||||
(key, value, lockstring) or (key, value, lockstring, default_access).
|
||||
to set as Attributes on the new object.
|
||||
to set as Attributes on the new object.
|
||||
nattributes (list): Non-persistent tuples on the form (key, value). Note that
|
||||
adding this rarely makes sense since this data will not survive a reload.
|
||||
|
||||
|
|
@ -229,8 +229,9 @@ def create_script(
|
|||
report_to (Object): The object to return error messages to.
|
||||
desc (str): Optional description of script
|
||||
tags (list): List of tags or tuples (tag, category).
|
||||
attributes (list): List if tuples (key, value) or (key, value, category)
|
||||
(key, value, lockstring) or (key, value, lockstring, default_access).
|
||||
attributes (list): List of tuples `(key, value)`, `(key, value, category)`,
|
||||
`(key, value, category, lockstring)` or
|
||||
`(key, value, category, lockstring, default_access)`.
|
||||
|
||||
Returns:
|
||||
script (obj): An instance of the script created
|
||||
|
|
|
|||
|
|
@ -78,6 +78,45 @@ class TestCreateScript(EvenniaTest):
|
|||
assert script.key == "test_script"
|
||||
script.stop()
|
||||
|
||||
def test_attr_creation_func(self):
|
||||
"""
|
||||
Test of assigning attributes during creation
|
||||
|
||||
"""
|
||||
attrvalue = {'test1': 1, 'test2': 'boo'}
|
||||
|
||||
# creation-function direct call
|
||||
script = create.create_script(
|
||||
key='script_broken',
|
||||
attributes=[
|
||||
('testname', attrvalue, '')
|
||||
]
|
||||
)
|
||||
self.assertTrue(script)
|
||||
self.assertEqual(script.db.testname, None) # since the category is '' and not None
|
||||
self.assertEqual(script.attributes.get("testname", category=''), attrvalue)
|
||||
script.stop()
|
||||
|
||||
def test_attr_method_creation_malformed(self):
|
||||
"""
|
||||
Adding the wrong type for one attribute-tuple element
|
||||
|
||||
"""
|
||||
attrvalue = {'test1': 1, 'test2': 'boo'}
|
||||
|
||||
# method-based creation
|
||||
script, err = DefaultScript.create(
|
||||
'scripttest2',
|
||||
attributes=[
|
||||
# test of wrong syntax - last element should be bool
|
||||
('testname', attrvalue, None, '', '')
|
||||
]
|
||||
)
|
||||
self.assertFalse(err)
|
||||
self.assertTrue(script)
|
||||
self.assertEqual(script.db.testname, attrvalue)
|
||||
script.stop()
|
||||
|
||||
|
||||
class TestCreateHelpEntry(TestCase):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue