mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-08 08:20:28 +03:00
update: test metadata creation using internal and external templates
There is a hardcoded template in update.py, and there is also the possibility for the user to create a template.yml. This tests both of them and cleans up the related code a bit. #352 !310
This commit is contained in:
parent
96aacf1752
commit
7bd171480f
2 changed files with 108 additions and 42 deletions
|
|
@ -491,6 +491,65 @@ class UpdateTest(unittest.TestCase):
|
|||
foundtest = True
|
||||
self.assertTrue(foundtest)
|
||||
|
||||
def test_create_metadata_from_template(self):
|
||||
tmpdir = os.path.join(localmodule, '.testfiles')
|
||||
if not os.path.exists(tmpdir):
|
||||
os.makedirs(tmpdir)
|
||||
tmptestsdir = tempfile.mkdtemp(prefix='test_create_metadata_from_template-',
|
||||
dir=tmpdir)
|
||||
print('tmptestsdir', tmptestsdir)
|
||||
os.chdir(tmptestsdir)
|
||||
os.mkdir('repo')
|
||||
shutil.copy(os.path.join(localmodule, 'tests', 'urzip.apk'), 'repo')
|
||||
|
||||
config = dict()
|
||||
fdroidserver.common.fill_config_defaults(config)
|
||||
config['ndk_paths'] = dict()
|
||||
config['accepted_formats'] = ['json', 'txt', 'yml']
|
||||
fdroidserver.common.config = config
|
||||
fdroidserver.update.config = config
|
||||
|
||||
fdroidserver.update.options = type('', (), {})()
|
||||
fdroidserver.update.options.clean = True
|
||||
fdroidserver.update.options.delete_unknown = False
|
||||
fdroidserver.update.options.rename_apks = False
|
||||
fdroidserver.update.options.allow_disabled_algorithms = False
|
||||
|
||||
apps = fdroidserver.metadata.read_metadata(xref=True)
|
||||
self.assertEqual(0, len(apps))
|
||||
knownapks = fdroidserver.common.KnownApks()
|
||||
apks, cachechanged = fdroidserver.update.process_apks({}, 'repo', knownapks, False)
|
||||
self.assertEqual(1, len(apks))
|
||||
apk = apks[0]
|
||||
|
||||
# test using internal template
|
||||
fdroidserver.update.create_metadata_from_template(apk)
|
||||
self.assertTrue(os.path.exists('metadata/info.guardianproject.urzip.yml'))
|
||||
apps = fdroidserver.metadata.read_metadata(xref=True)
|
||||
self.assertEqual(1, len(apps))
|
||||
for app in apps.values():
|
||||
self.assertEqual('urzip', app['Name'])
|
||||
self.assertEqual(1, len(app['Categories']))
|
||||
break
|
||||
|
||||
# test using external template.yml
|
||||
os.remove('metadata/info.guardianproject.urzip.yml')
|
||||
self.assertFalse(os.path.exists('metadata/info.guardianproject.urzip.yml'))
|
||||
shutil.copy(os.path.join(localmodule, 'examples', 'template.yml'), tmptestsdir)
|
||||
fdroidserver.update.create_metadata_from_template(apk)
|
||||
self.assertTrue(os.path.exists('metadata/info.guardianproject.urzip.yml'))
|
||||
apps = fdroidserver.metadata.read_metadata(xref=True)
|
||||
self.assertEqual(1, len(apps))
|
||||
for app in apps.values():
|
||||
self.assertEqual('urzip', app['Name'])
|
||||
self.assertEqual(1, len(app['Categories']))
|
||||
self.assertEqual('Internet', app['Categories'][0])
|
||||
break
|
||||
with open('metadata/info.guardianproject.urzip.yml') as fp:
|
||||
data = yaml.load(fp)
|
||||
self.assertEqual('urzip', data['Name'])
|
||||
self.assertEqual('urzip', data['Summary'])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = optparse.OptionParser()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue