From 238f0482574e5942427dc7ae8f68c4d9c2bdebc7 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 24 Jun 2020 20:54:16 +0200 Subject: [PATCH] update: fix crash when liberapay: or open_collective: not in FUNDING.yml closes #799 --- fdroidserver/update.py | 6 ++++-- tests/update.TestCase | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/fdroidserver/update.py b/fdroidserver/update.py index 4c371da9..06ed01de 100644 --- a/fdroidserver/update.py +++ b/fdroidserver/update.py @@ -936,8 +936,10 @@ def insert_funding_yml_donation_links(apps): if s: app['OpenCollective'] = s if not app.get('Donate'): - del(data['liberapay']) - del(data['open_collective']) + if 'liberapay' in data: + del(data['liberapay']) + if 'open_collective' in data: + del(data['open_collective']) # this tuple provides a preference ordering for k in ('custom', 'github', 'patreon', 'community_bridge', 'ko_fi', 'issuehunt'): v = data.get(k) diff --git a/tests/update.TestCase b/tests/update.TestCase index de2361f9..eee01734 100755 --- a/tests/update.TestCase +++ b/tests/update.TestCase @@ -1019,6 +1019,47 @@ class UpdateTest(unittest.TestCase): for field in DONATION_FIELDS: self.assertEqual('keepme', app.get(field)) + def test_insert_funding_yml_donation_links_one_at_a_time(self): + """Exercise the FUNDING.yml code one entry at a time""" + testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir) + os.chdir(testdir) + os.mkdir('build') + + app = fdroidserver.metadata.App() + app.id = 'fake.app.id' + apps = {app.id: app} + os.mkdir(os.path.join('build', app.id)) + fdroidserver.update.insert_funding_yml_donation_links(apps) + for field in DONATION_FIELDS: + self.assertIsNone(app.get(field)) + + content = textwrap.dedent(""" + community_bridge: 'blah-de-blah' + github: USERNAME + issuehunt: USERNAME + ko_fi: USERNAME + liberapay: USERNAME + open_collective: USERNAME + patreon: USERNAME + """) + for line in content.split('\n'): + if not line: + continue + app = fdroidserver.metadata.App() + app.id = 'fake.app.id' + apps = {app.id: app} + with open(os.path.join('build', app.id, 'FUNDING.yml'), 'w') as fp: + fp.write(line) + data = yaml.load(line) + fdroidserver.update.insert_funding_yml_donation_links(apps) + if 'liberapay' in data: + self.assertEqual(data['liberapay'], app.get('Liberapay')) + elif 'open_collective' in data: + self.assertEqual(data['open_collective'], app.get('OpenCollective')) + else: + for v in data.values(): + self.assertEqual(app.get('Donate', '').split('/')[-1], v) + def test_insert_funding_yml_donation_links_with_corrupt_file(self): testdir = tempfile.mkdtemp(prefix=inspect.currentframe().f_code.co_name, dir=self.tmpdir) os.chdir(testdir)