mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-20 13:50:12 +01:00
make metadata template behaves well for empty values
This commit is contained in:
parent
051596dd0d
commit
e2fed09af1
@ -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__))
|
||||
|
Loading…
Reference in New Issue
Block a user