mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-10 17:30:11 +01:00
18f3acc32e
There is no longer any reason for these to be intertwined. This deliberately avoids touching some files as much as possible because they are super tangled and due to be replaced. Those files are: * fdroidserver/build.py * fdroidserver/update.py # Conflicts: # tests/testcommon.py # Conflicts: # fdroidserver/btlog.py # fdroidserver/import_subcommand.py
92 lines
2.8 KiB
Python
Executable File
92 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# http://www.drdobbs.com/testing/unit-testing-with-python/240165163
|
|
|
|
import inspect
|
|
import logging
|
|
import os
|
|
import shutil
|
|
import sys
|
|
import unittest
|
|
|
|
|
|
localmodule = os.path.realpath(
|
|
os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')
|
|
)
|
|
print('localmodule: ' + localmodule)
|
|
if localmodule not in sys.path:
|
|
sys.path.insert(0, localmodule)
|
|
|
|
import fdroidserver.init
|
|
from testcommon import mkdtemp, parse_args_for_test
|
|
|
|
|
|
class InitTest(unittest.TestCase):
|
|
'''fdroidserver/init.py'''
|
|
|
|
def setUp(self):
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
self.basedir = os.path.join(localmodule, 'tests')
|
|
fdroidserver.common.config = None
|
|
fdroidserver.init.config = None
|
|
self._td = mkdtemp()
|
|
self.testdir = self._td.name
|
|
|
|
def tearDown(self):
|
|
self._td.cleanup()
|
|
os.chdir(self.basedir)
|
|
|
|
def test_disable_in_config(self):
|
|
os.chdir(self.testdir)
|
|
with open('config.yml', 'w') as fp:
|
|
fp.write('keystore: NONE\n')
|
|
fp.write('keypass: mysupersecrets\n')
|
|
os.chmod('config.yml', 0o600)
|
|
config = fdroidserver.common.read_config()
|
|
self.assertEqual('NONE', config['keystore'])
|
|
self.assertEqual('mysupersecrets', config['keypass'])
|
|
fdroidserver.init.disable_in_config('keypass', 'comment')
|
|
with open(fp.name) as fp:
|
|
self.assertTrue('#keypass:' in fp.read())
|
|
fdroidserver.common.config = None
|
|
config = fdroidserver.common.read_config()
|
|
self.assertIsNone(config.get('keypass'))
|
|
|
|
@unittest.skipIf(os.name == 'nt', "calling main() like this hangs on Windows")
|
|
def test_main_in_empty_dir(self):
|
|
"""Test that `fdroid init` will find apksigner and add it to the config"""
|
|
os.chdir(self.testdir)
|
|
|
|
shutil.copy(os.path.join(self.basedir, 'keystore.jks'), self.testdir)
|
|
|
|
bindir = os.path.join(os.getcwd(), 'bin')
|
|
os.mkdir(bindir)
|
|
apksigner = os.path.join(bindir, 'apksigner')
|
|
open(apksigner, 'w').close()
|
|
os.chmod(apksigner, 0o755)
|
|
os.environ['PATH'] = bindir
|
|
|
|
sys.argv = ['fdroid init', '--keystore', 'keystore.jks', '--repo-keyalias=sova']
|
|
fdroidserver.init.main()
|
|
self.assertEqual(apksigner, fdroidserver.init.config.get('apksigner'))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
os.chdir(os.path.dirname(__file__))
|
|
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument(
|
|
"-v",
|
|
"--verbose",
|
|
action="store_true",
|
|
default=False,
|
|
help="Spew out even more information than normal",
|
|
)
|
|
fdroidserver.init.options = parse_args_for_test(parser, sys.argv)
|
|
|
|
newSuite = unittest.TestSuite()
|
|
newSuite.addTest(unittest.makeSuite(InitTest))
|
|
unittest.main(failfast=False)
|