mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 23:23:27 +02:00
metadata: remove non-values from Builds: entries
This commit is contained in:
parent
689786eea4
commit
fac7ceffe3
@ -1077,8 +1077,14 @@ def _format_multiline(value):
|
|||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
|
||||||
|
def _format_list(value):
|
||||||
|
"""TYPE_LIST should not contain null values."""
|
||||||
|
return [v for v in value if v]
|
||||||
|
|
||||||
|
|
||||||
def _format_script(value):
|
def _format_script(value):
|
||||||
"""TYPE_SCRIPT with one value are converted to YAML string values."""
|
"""TYPE_SCRIPT with one value are converted to YAML string values."""
|
||||||
|
value = [v for v in value if v]
|
||||||
if len(value) == 1:
|
if len(value) == 1:
|
||||||
return value[0]
|
return value[0]
|
||||||
return value
|
return value
|
||||||
@ -1175,6 +1181,8 @@ def _builds_to_yaml(app):
|
|||||||
_flagtype = flagtype(field)
|
_flagtype = flagtype(field)
|
||||||
if _flagtype == TYPE_MULTILINE:
|
if _flagtype == TYPE_MULTILINE:
|
||||||
v = _format_multiline(v)
|
v = _format_multiline(v)
|
||||||
|
elif _flagtype == TYPE_LIST:
|
||||||
|
v = _format_list(v)
|
||||||
elif _flagtype == TYPE_SCRIPT:
|
elif _flagtype == TYPE_SCRIPT:
|
||||||
v = _format_script(v)
|
v = _format_script(v)
|
||||||
elif _flagtype == TYPE_STRINGMAP:
|
elif _flagtype == TYPE_STRINGMAP:
|
||||||
|
@ -1943,6 +1943,24 @@ class MetadataTest(unittest.TestCase):
|
|||||||
'\none\ntwo\nthree\n',
|
'\none\ntwo\nthree\n',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_format_list_empty(self):
|
||||||
|
self.assertEqual(metadata._format_list(['', None]), list())
|
||||||
|
|
||||||
|
def test_format_list_one_empty(self):
|
||||||
|
self.assertEqual(metadata._format_list(['foo', None]), ['foo'])
|
||||||
|
|
||||||
|
def test_format_list_two(self):
|
||||||
|
self.assertEqual(metadata._format_list(['2', '1']), ['2', '1'])
|
||||||
|
|
||||||
|
def test_format_list_newline(self):
|
||||||
|
self.assertEqual(metadata._format_list(['one\ntwo']), ['one\ntwo'])
|
||||||
|
|
||||||
|
def test_format_list_newline_char(self):
|
||||||
|
self.assertEqual(metadata._format_list(['one\\ntwo']), ['one\\ntwo'])
|
||||||
|
|
||||||
|
def test_format_script_empty(self):
|
||||||
|
self.assertEqual(metadata._format_script(['', None]), list())
|
||||||
|
|
||||||
def test_format_script_newline(self):
|
def test_format_script_newline(self):
|
||||||
self.assertEqual(metadata._format_script(['one\ntwo']), 'one\ntwo')
|
self.assertEqual(metadata._format_script(['one\ntwo']), 'one\ntwo')
|
||||||
|
|
||||||
@ -2086,6 +2104,18 @@ class MetadataTest(unittest.TestCase):
|
|||||||
metadata._builds_to_yaml(app), [{'versionCode': 0, 'gradle': ['false']}]
|
metadata._builds_to_yaml(app), [{'versionCode': 0, 'gradle': ['false']}]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_builds_to_yaml_stripped(self):
|
||||||
|
self.assertEqual(
|
||||||
|
metadata._builds_to_yaml(
|
||||||
|
{
|
||||||
|
'Builds': [
|
||||||
|
metadata.Build({'versionCode': 0, 'rm': [None], 'init': ['']})
|
||||||
|
]
|
||||||
|
}
|
||||||
|
),
|
||||||
|
[{'versionCode': 0}],
|
||||||
|
)
|
||||||
|
|
||||||
def test_builds_to_yaml(self):
|
def test_builds_to_yaml(self):
|
||||||
"""Include one of each flag type with a valid value."""
|
"""Include one of each flag type with a valid value."""
|
||||||
app = {
|
app = {
|
||||||
|
Loading…
Reference in New Issue
Block a user