Commit 39c589fb authored by Michael Pöhn's avatar Michael Pöhn
Browse files

Merge branch 'update-create-template' into 'master'

make metadata template behave well for empty values

Closes #681

See merge request !657
parents 8cfeeab4 e2fed09a
Pipeline #72677414 passed with stage
in 17 minutes and 45 seconds
......@@ -1869,6 +1869,11 @@ def create_metadata_from_template(apk):
r'\1 ' + apk['packageName'],
metatxt,
flags=re.IGNORECASE | re.MULTILINE)
# make sure unset string values will be interpreted as blank strings
str_fields = [x for x in metadata.yaml_app_fields if metadata.fieldtype(x) == metadata.TYPE_STRING]
metatxt = re.sub(r'^(' + '|'.join(str_fields) + '):\\s*$',
r"\1: ''", metatxt,
flags=re.MULTILINE)
with open(os.path.join('metadata', apk['packageName'] + '.yml'), 'w') as f:
f.write(metatxt)
else:
......
......@@ -15,8 +15,10 @@ import tempfile
import unittest
import yaml
import zipfile
import textwrap
from binascii import unhexlify
from distutils.version import LooseVersion
from testcommon import TmpCwd
localmodule = os.path.realpath(
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..'))
......@@ -833,6 +835,87 @@ class UpdateTest(unittest.TestCase):
icons_src = fdroidserver.update._get_apk_icons_src('urzip-release.apk', None)
assert icons_src == {}
def test_create_metadata_from_template_empty_keys(self):
apk = {'packageName': 'rocks.janicerand'}
with tempfile.TemporaryDirectory() as tmpdir, TmpCwd(tmpdir):
os.mkdir('metadata')
with open('template.yml', 'w') as f:
f.write(textwrap.dedent('''\
Disabled:
Provides:
License:
AuthorName:
AuthorEmail:
AuthorWebSite:
WebSite:
SourceCode:
IssueTracker:
Translation:
Changelog:
Donate:
FlattrID:
LiberapayID:
Bitcoin:
Litecoin:
Name:
AutoName:
Summary:
RequiresRoot:
RepoType:
Repo:
Binaries:
Builds:
ArchivePolicy:
AutoUpdateMode:
UpdateCheckMode:
UpdateCheckIgnore:
VercodeOperation:
UpdateCheckName:
UpdateCheckData:
CurrentVersion:
CurrentVersionCode:
NoSourceSince:
'''))
fdroidserver.update.create_metadata_from_template(apk)
with open(os.path.join('metadata', 'rocks.janicerand.yml')) as f:
metadata_content = yaml.load(f)
self.maxDiff = None
self.assertDictEqual(metadata_content,
{'ArchivePolicy': '',
'AuthorEmail': '',
'AuthorName': '',
'AuthorWebSite': '',
'AutoName': 'rocks.janicerand',
'AutoUpdateMode': '',
'Binaries': '',
'Bitcoin': '',
'Builds': '',
'Changelog': '',
'CurrentVersion': '',
'CurrentVersionCode': '',
'Disabled': '',
'Donate': '',
'FlattrID': '',
'IssueTracker': '',
'LiberapayID': '',
'License': '',
'Litecoin': '',
'Name': 'rocks.janicerand',
'NoSourceSince': '',
'Provides': '',
'Repo': '',
'RepoType': '',
'RequiresRoot': '',
'SourceCode': '',
'Summary': 'rocks.janicerand',
'Translation': '',
'UpdateCheckData': '',
'UpdateCheckIgnore': '',
'UpdateCheckMode': '',
'UpdateCheckName': '',
'VercodeOperation': '',
'WebSite': ''})
if __name__ == "__main__":
os.chdir(os.path.dirname(__file__))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment