metadata: case-insensitive sort for AntiFeatures Categories

This commit is contained in:
Hans-Christoph Steiner 2023-05-24 14:57:32 +02:00 committed by Michael Pöhn
parent 2efc9437ab
commit d3521d7374
2 changed files with 17 additions and 1 deletions

View File

@ -1127,7 +1127,7 @@ def _format_stringmap(appid, field, stringmap, versionCode=None):
make_list = False
break
if make_list:
return outlist
return sorted(outlist, key=str.lower)
return stringmap
@ -1208,6 +1208,8 @@ def _app_to_yaml(app):
if field == 'Builds':
if app.get('Builds'):
cm.update({field: _builds_to_yaml(app)})
elif field == 'Categories':
cm[field] = sorted(value, key=str.lower)
elif field == 'CurrentVersionCode':
cm[field] = _field_to_yaml(TYPE_INT, value)
elif field == 'AntiFeatures':

View File

@ -2019,6 +2019,20 @@ class MetadataTest(unittest.TestCase):
appid, field, {afname: {'uz': 'a', locale: 'b', 'zh': 'c'}}, versionCode
)
def test_app_to_yaml_one_category(self):
"""Categories does not get simplified to string when outputting YAML."""
self.assertEqual(
metadata._app_to_yaml({'Categories': ['one']}),
{'Categories': ['one']},
)
def test_app_to_yaml_categories(self):
"""Sort case-insensitive before outputting YAML."""
self.assertEqual(
metadata._app_to_yaml({'Categories': ['c', 'a', 'B']}),
{'Categories': ['a', 'B', 'c']},
)
class PostMetadataParseTest(unittest.TestCase):
"""Test the functions that post process the YAML input.