mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-10 01:00:29 +03:00
split out options from read_config()
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
This commit is contained in:
parent
685efa23d4
commit
18f3acc32e
53 changed files with 317 additions and 265 deletions
|
|
@ -28,7 +28,7 @@ import fdroidserver.common
|
|||
import fdroidserver.metadata
|
||||
import fdroidserver.scanner
|
||||
import fdroidserver.vmtools
|
||||
from testcommon import mkdtemp
|
||||
from testcommon import mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
class FakeProcess:
|
||||
|
|
@ -561,7 +561,7 @@ class BuildTest(unittest.TestCase):
|
|||
os.chdir(self.testdir)
|
||||
os.mkdir("build")
|
||||
|
||||
config = fdroidserver.common.get_config()
|
||||
config = fdroidserver.common.read_config()
|
||||
config['sdk_path'] = os.getenv('ANDROID_HOME')
|
||||
config['ndk_paths'] = {'r10d': os.getenv('ANDROID_NDK_HOME')}
|
||||
fdroidserver.common.config = config
|
||||
|
|
@ -1113,7 +1113,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(BuildTest))
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
os.chdir(self.basedir)
|
||||
|
||||
def test_autoupdatemode_no_suffix(self):
|
||||
fdroidserver.checkupdates.options = mock.Mock()
|
||||
fdroidserver.checkupdates.options.auto = 'bleh'
|
||||
fdroidserver.checkupdates.config = {}
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
|
|
@ -51,7 +49,7 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
):
|
||||
with mock.patch('fdroidserver.metadata.write_metadata', mock.Mock()):
|
||||
with mock.patch('subprocess.call', lambda cmd: 0):
|
||||
fdroidserver.checkupdates.checkupdates_app(app)
|
||||
fdroidserver.checkupdates.checkupdates_app(app, auto=True)
|
||||
|
||||
build = app['Builds'][-1]
|
||||
self.assertEqual(build.versionName, '1.1.9')
|
||||
|
|
@ -63,15 +61,13 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
with mock.patch('fdroidserver.metadata.write_metadata', mock.Mock()):
|
||||
with mock.patch('subprocess.call', lambda cmd: 0):
|
||||
with self.assertRaises(FDroidException):
|
||||
fdroidserver.checkupdates.checkupdates_app(app)
|
||||
fdroidserver.checkupdates.checkupdates_app(app, auto=True)
|
||||
|
||||
build = app['Builds'][-1]
|
||||
self.assertEqual(build.versionName, '1.1.9')
|
||||
self.assertEqual(build.commit, '1.1.9')
|
||||
|
||||
def test_autoupdatemode_suffix(self):
|
||||
fdroidserver.checkupdates.options = mock.Mock()
|
||||
fdroidserver.checkupdates.options.auto = 'bleh'
|
||||
fdroidserver.checkupdates.config = {}
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
|
|
@ -92,15 +88,13 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
):
|
||||
with mock.patch('fdroidserver.metadata.write_metadata', mock.Mock()):
|
||||
with mock.patch('subprocess.call', lambda cmd: 0):
|
||||
fdroidserver.checkupdates.checkupdates_app(app)
|
||||
fdroidserver.checkupdates.checkupdates_app(app, auto=True)
|
||||
|
||||
build = app['Builds'][-1]
|
||||
self.assertEqual(build.versionName, '1.1.9.10109-fdroid')
|
||||
self.assertEqual(build.commit, 'v1.1.9_10109')
|
||||
|
||||
def test_autoupdate_multi_variants(self):
|
||||
fdroidserver.checkupdates.options = mock.Mock()
|
||||
fdroidserver.checkupdates.options.auto = 'bleh'
|
||||
fdroidserver.checkupdates.config = {}
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
|
|
@ -133,7 +127,7 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
):
|
||||
with mock.patch('fdroidserver.metadata.write_metadata', mock.Mock()):
|
||||
with mock.patch('subprocess.call', lambda cmd: 0):
|
||||
fdroidserver.checkupdates.checkupdates_app(app)
|
||||
fdroidserver.checkupdates.checkupdates_app(app, auto=True)
|
||||
|
||||
build = app['Builds'][-2]
|
||||
self.assertEqual(build.versionName, '1.1.9')
|
||||
|
|
@ -149,8 +143,6 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
self.assertEqual(app.CurrentVersionCode, 101093)
|
||||
|
||||
def test_checkupdates_app_http(self):
|
||||
fdroidserver.checkupdates.options = mock.Mock()
|
||||
fdroidserver.checkupdates.options.auto = 'bleh'
|
||||
fdroidserver.checkupdates.config = {}
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
|
|
@ -164,7 +156,7 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
'fdroidserver.checkupdates.check_http', lambda app: (None, 'bla')
|
||||
):
|
||||
with self.assertRaises(FDroidException):
|
||||
fdroidserver.checkupdates.checkupdates_app(app)
|
||||
fdroidserver.checkupdates.checkupdates_app(app, auto=True)
|
||||
|
||||
with mock.patch(
|
||||
'fdroidserver.checkupdates.check_http', lambda app: ('1.1.9', 10109)
|
||||
|
|
@ -173,12 +165,10 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
'fdroidserver.metadata.write_metadata', mock.Mock()
|
||||
) as wrmock:
|
||||
with mock.patch('subprocess.call', lambda cmd: 0):
|
||||
fdroidserver.checkupdates.checkupdates_app(app)
|
||||
fdroidserver.checkupdates.checkupdates_app(app, auto=True)
|
||||
wrmock.assert_called_with(app.metadatapath, app)
|
||||
|
||||
def test_checkupdates_app_tags(self):
|
||||
fdroidserver.checkupdates.options = mock.Mock()
|
||||
fdroidserver.checkupdates.options.auto = 'bleh'
|
||||
fdroidserver.checkupdates.config = {}
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
|
|
@ -199,7 +189,7 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
lambda app, pattern: (None, 'bla', None),
|
||||
):
|
||||
with self.assertRaises(FDroidException):
|
||||
fdroidserver.checkupdates.checkupdates_app(app)
|
||||
fdroidserver.checkupdates.checkupdates_app(app, auto=True)
|
||||
|
||||
with mock.patch(
|
||||
'fdroidserver.checkupdates.check_tags',
|
||||
|
|
@ -207,15 +197,13 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
):
|
||||
with mock.patch('fdroidserver.metadata.write_metadata', mock.Mock()):
|
||||
with mock.patch('subprocess.call', lambda cmd: 0):
|
||||
fdroidserver.checkupdates.checkupdates_app(app)
|
||||
fdroidserver.checkupdates.checkupdates_app(app, auto=True)
|
||||
|
||||
build = app['Builds'][-1]
|
||||
self.assertEqual(build.versionName, '1.1.9')
|
||||
self.assertEqual(build.commit, 'v1.1.9')
|
||||
|
||||
def test_check_http(self):
|
||||
fdroidserver.checkupdates.options = mock.Mock()
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
app.id = 'loop.starts.shooting'
|
||||
app.metadatapath = 'metadata/' + app.id + '.yml'
|
||||
|
|
@ -242,8 +230,6 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
fdroidserver.checkupdates.check_http(app)
|
||||
|
||||
def test_check_http_ignore(self):
|
||||
fdroidserver.checkupdates.options = mock.Mock()
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
app.id = 'loop.starts.shooting'
|
||||
app.metadatapath = 'metadata/' + app.id + '.yml'
|
||||
|
|
@ -259,8 +245,6 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
self.assertEqual(vername, None)
|
||||
|
||||
def test_check_tags_data(self):
|
||||
fdroidserver.checkupdates.options = mock.Mock()
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
app.id = 'loop.starts.shooting'
|
||||
app.metadatapath = 'metadata/' + app.id + '.yml'
|
||||
|
|
@ -336,6 +320,7 @@ class CheckupdatesTest(unittest.TestCase):
|
|||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
from testcommon import parse_args_for_test
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
|
|
@ -345,7 +330,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(CheckupdatesTest))
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import fdroidserver.index
|
|||
import fdroidserver.signindex
|
||||
import fdroidserver.common
|
||||
import fdroidserver.metadata
|
||||
from testcommon import TmpCwd, mkdtemp
|
||||
from testcommon import TmpCwd, mkdtemp, parse_args_for_test
|
||||
from fdroidserver.common import ANTIFEATURES_CONFIG_NAME, CATEGORIES_CONFIG_NAME
|
||||
from fdroidserver.exception import FDroidException, VCSException,\
|
||||
MetaDataException, VerificationException
|
||||
|
|
@ -491,7 +491,7 @@ class CommonTest(unittest.TestCase):
|
|||
|
||||
def test_signjar(self):
|
||||
_mock_common_module_options_instance()
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
config['jarsigner'] = fdroidserver.common.find_sdk_tools_cmd('jarsigner')
|
||||
fdroidserver.common.config = config
|
||||
fdroidserver.signindex.config = config
|
||||
|
|
@ -512,7 +512,7 @@ class CommonTest(unittest.TestCase):
|
|||
|
||||
def test_verify_apk_signature(self):
|
||||
_mock_common_module_options_instance()
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
fdroidserver.common.config = config
|
||||
|
||||
self.assertTrue(fdroidserver.common.verify_apk_signature('bad-unicode-πÇÇ现代通用字-български-عربي1.apk'))
|
||||
|
|
@ -535,7 +535,7 @@ class CommonTest(unittest.TestCase):
|
|||
|
||||
def test_verify_old_apk_signature(self):
|
||||
_mock_common_module_options_instance()
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
config['jarsigner'] = fdroidserver.common.find_sdk_tools_cmd('jarsigner')
|
||||
fdroidserver.common.config = config
|
||||
|
||||
|
|
@ -556,7 +556,7 @@ class CommonTest(unittest.TestCase):
|
|||
|
||||
def test_verify_jar_signature(self):
|
||||
"""Sign entry.jar and make sure it validates"""
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
config['jarsigner'] = fdroidserver.common.find_sdk_tools_cmd('jarsigner')
|
||||
config['keystore'] = os.path.join(self.basedir, 'keystore.jks')
|
||||
config['repo_keyalias'] = 'sova'
|
||||
|
|
@ -574,7 +574,7 @@ class CommonTest(unittest.TestCase):
|
|||
|
||||
def test_verify_jar_signature_fails(self):
|
||||
"""Test verify_jar_signature fails on unsigned and deprecated algorithms"""
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
config['jarsigner'] = fdroidserver.common.find_sdk_tools_cmd('jarsigner')
|
||||
fdroidserver.common.config = config
|
||||
source_dir = os.path.join(self.basedir, 'signindex')
|
||||
|
|
@ -584,7 +584,7 @@ class CommonTest(unittest.TestCase):
|
|||
fdroidserver.common.verify_jar_signature(testfile)
|
||||
|
||||
def test_verify_deprecated_jar_signature(self):
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
config['jarsigner'] = fdroidserver.common.find_sdk_tools_cmd('jarsigner')
|
||||
fdroidserver.common.config = config
|
||||
source_dir = os.path.join(self.basedir, 'signindex')
|
||||
|
|
@ -597,7 +597,7 @@ class CommonTest(unittest.TestCase):
|
|||
fdroidserver.common.verify_deprecated_jar_signature(testfile)
|
||||
|
||||
def test_verify_apks(self):
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
fdroidserver.common.config = config
|
||||
_mock_common_module_options_instance()
|
||||
|
||||
|
|
@ -907,7 +907,7 @@ class CommonTest(unittest.TestCase):
|
|||
|
||||
def test_sign_apk(self):
|
||||
_mock_common_module_options_instance()
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
if 'apksigner' not in config:
|
||||
self.skipTest('SKIPPING test_sign_apk, apksigner not installed!')
|
||||
|
||||
|
|
@ -978,7 +978,7 @@ class CommonTest(unittest.TestCase):
|
|||
@unittest.skipIf(os.getuid() == 0, 'This is meaningless when run as root')
|
||||
def test_sign_apk_fail(self):
|
||||
_mock_common_module_options_instance()
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
if 'apksigner' not in config:
|
||||
self.skipTest('SKIPPING test_sign_apk_fail, apksigner not installed!')
|
||||
|
||||
|
|
@ -1002,7 +1002,7 @@ class CommonTest(unittest.TestCase):
|
|||
|
||||
def test_sign_apk_corrupt(self):
|
||||
_mock_common_module_options_instance()
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
if 'apksigner' not in config:
|
||||
self.skipTest('SKIPPING test_sign_apk_corrupt, apksigner not installed!')
|
||||
|
||||
|
|
@ -1029,7 +1029,7 @@ class CommonTest(unittest.TestCase):
|
|||
def test_resign_apk(self):
|
||||
"""When using apksigner, it should resign signed APKs"""
|
||||
_mock_common_module_options_instance()
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
if 'apksigner' not in config:
|
||||
self.skipTest('SKIPPING test_resign_apk, apksigner not installed!')
|
||||
|
||||
|
|
@ -1935,7 +1935,7 @@ class CommonTest(unittest.TestCase):
|
|||
os.chdir(self.tmpdir)
|
||||
self.assertFalse(os.path.exists('config.yml'))
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertFalse(config.get('update_stats'))
|
||||
self.assertIsNotNone(config.get('char_limits'))
|
||||
|
||||
|
|
@ -1945,7 +1945,7 @@ class CommonTest(unittest.TestCase):
|
|||
open('config.yml', 'w').close()
|
||||
self.assertTrue(os.path.exists('config.yml'))
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertFalse(config.get('update_stats'))
|
||||
self.assertIsNotNone(config.get('char_limits'))
|
||||
|
||||
|
|
@ -1956,7 +1956,7 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write('apksigner: yml')
|
||||
self.assertTrue(os.path.exists('config.yml'))
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertEqual('yml', config.get('apksigner'))
|
||||
|
||||
def test_with_config_yml_utf8(self):
|
||||
|
|
@ -1967,7 +1967,7 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write('apksigner: ' + teststr)
|
||||
self.assertTrue(os.path.exists('config.yml'))
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertEqual(teststr, config.get('apksigner'))
|
||||
|
||||
def test_with_config_yml_utf8_as_ascii(self):
|
||||
|
|
@ -1978,7 +1978,7 @@ class CommonTest(unittest.TestCase):
|
|||
yaml.dump({'apksigner': teststr}, fp)
|
||||
self.assertTrue(os.path.exists('config.yml'))
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertEqual(teststr, config.get('apksigner'))
|
||||
|
||||
def test_with_config_yml_with_env_var(self):
|
||||
|
|
@ -1990,20 +1990,20 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write("""keypass: {'env': 'SECRET'}""")
|
||||
self.assertTrue(os.path.exists('config.yml'))
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertEqual(os.getenv('SECRET', 'fail'), config.get('keypass'))
|
||||
|
||||
def test_with_config_yml_is_dict(self):
|
||||
os.chdir(self.tmpdir)
|
||||
Path('config.yml').write_text('apksigner = /placeholder/path')
|
||||
with self.assertRaises(TypeError):
|
||||
fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
fdroidserver.common.read_config()
|
||||
|
||||
def test_with_config_yml_is_not_mixed_type(self):
|
||||
os.chdir(self.tmpdir)
|
||||
Path('config.yml').write_text('k: v\napksigner = /placeholder/path')
|
||||
with self.assertRaises(yaml.scanner.ScannerError):
|
||||
fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
fdroidserver.common.read_config()
|
||||
|
||||
def test_with_config_py(self):
|
||||
"""Make sure it is still possible to use config.py alone."""
|
||||
|
|
@ -2012,7 +2012,7 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write('apksigner = "py"')
|
||||
self.assertFalse(os.path.exists('config.yml'))
|
||||
self.assertTrue(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertEqual("py", config.get('apksigner'))
|
||||
|
||||
def test_config_perm_warning(self):
|
||||
|
|
@ -2022,7 +2022,7 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write('keystore: foo.jks')
|
||||
self.assertTrue(os.path.exists(fp.name))
|
||||
os.chmod(fp.name, 0o666)
|
||||
fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
fdroidserver.common.read_config()
|
||||
os.remove(fp.name)
|
||||
fdroidserver.common.config = None
|
||||
|
||||
|
|
@ -2030,7 +2030,7 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write('keystore = "foo.jks"')
|
||||
self.assertTrue(os.path.exists(fp.name))
|
||||
os.chmod(fp.name, 0o666)
|
||||
fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
fdroidserver.common.read_config()
|
||||
|
||||
def test_with_both_config_yml_py(self):
|
||||
"""If config.yml and config.py are present, config.py should be ignored."""
|
||||
|
|
@ -2041,7 +2041,7 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write('apksigner = "py"')
|
||||
self.assertTrue(os.path.exists('config.yml'))
|
||||
self.assertTrue(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertEqual('yml', config.get('apksigner'))
|
||||
|
||||
def test_config_repo_url(self):
|
||||
|
|
@ -2092,14 +2092,14 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write('apksigner: yml')
|
||||
self.assertTrue(os.path.exists(fp.name))
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertFalse('keypass' in config)
|
||||
self.assertEqual('yml', config.get('apksigner'))
|
||||
fdroidserver.common.write_to_config(config, 'keypass', 'mysecretpassword')
|
||||
with open(fp.name) as fp:
|
||||
print(fp.read())
|
||||
fdroidserver.common.config = None
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertEqual('mysecretpassword', config['keypass'])
|
||||
|
||||
def test_write_to_config_py(self):
|
||||
|
|
@ -2108,12 +2108,12 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write('apksigner = "py"')
|
||||
self.assertTrue(os.path.exists(fp.name))
|
||||
self.assertFalse(os.path.exists('config.yml'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertFalse('keypass' in config)
|
||||
self.assertEqual('py', config.get('apksigner'))
|
||||
fdroidserver.common.write_to_config(config, 'keypass', 'mysecretpassword')
|
||||
fdroidserver.common.config = None
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertEqual('mysecretpassword', config['keypass'])
|
||||
|
||||
def test_config_dict_with_int_keys(self):
|
||||
|
|
@ -2122,7 +2122,7 @@ class CommonTest(unittest.TestCase):
|
|||
fp.write('java_paths:\n 8: /usr/lib/jvm/java-8-openjdk\n')
|
||||
self.assertTrue(os.path.exists(fp.name))
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertEqual('/usr/lib/jvm/java-8-openjdk', config.get('java_paths', {}).get('8'))
|
||||
|
||||
@mock.patch.dict(os.environ, {'PATH': os.getenv('PATH')}, clear=True)
|
||||
|
|
@ -2200,7 +2200,7 @@ class CommonTest(unittest.TestCase):
|
|||
shutil.copy(os.path.join(self.basedir, '..', 'buildserver', 'config.buildserver.yml'),
|
||||
'config.yml')
|
||||
self.assertFalse(os.path.exists('config.py'))
|
||||
fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
fdroidserver.common.read_config()
|
||||
|
||||
def test_setup_status_output(self):
|
||||
os.chdir(self.tmpdir)
|
||||
|
|
@ -3267,11 +3267,43 @@ class ConfigOptionsScopeTest(unittest.TestCase):
|
|||
global options
|
||||
del options
|
||||
|
||||
def test_parse_args(self):
|
||||
"""Test that options is properly set up at the module-level and not global."""
|
||||
self.assertFalse('options' in globals())
|
||||
self.assertIsNone(fdroidserver.common.options)
|
||||
parser = ArgumentParser()
|
||||
fdroidserver.common.setup_global_opts(parser)
|
||||
with mock.patch('sys.argv', ['$0']):
|
||||
o = fdroidserver.common.parse_args(parser)
|
||||
self.assertEqual(o, fdroidserver.common.options)
|
||||
|
||||
# No function should set options as a global, and the global
|
||||
# keyword does not create the variable.
|
||||
global options
|
||||
with self.assertRaises(NameError):
|
||||
options
|
||||
self.assertFalse('options' in globals())
|
||||
|
||||
def test_parse_args_without_args(self):
|
||||
"""Test that the parsing function works fine when there are no args."""
|
||||
parser = ArgumentParser()
|
||||
fdroidserver.common.setup_global_opts(parser)
|
||||
with mock.patch('sys.argv', ['$0']):
|
||||
o = fdroidserver.common.parse_args(parser)
|
||||
self.assertFalse(o.verbose)
|
||||
|
||||
def test_parse_args_with_args(self):
|
||||
parser = ArgumentParser()
|
||||
fdroidserver.common.setup_global_opts(parser)
|
||||
with mock.patch('sys.argv', ['$0', '-v']):
|
||||
o = fdroidserver.common.parse_args(parser)
|
||||
self.assertTrue(o.verbose)
|
||||
|
||||
def test_get_config(self):
|
||||
"""Show how the module-level variables are initialized."""
|
||||
self.assertTrue('config' not in vars() and 'config' not in globals())
|
||||
self.assertIsNone(fdroidserver.common.config)
|
||||
config = fdroidserver.common.get_config()
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertIsNotNone(fdroidserver.common.config)
|
||||
self.assertEqual(dict, type(config))
|
||||
self.assertEqual(config, fdroidserver.common.config)
|
||||
|
|
@ -3281,7 +3313,7 @@ class ConfigOptionsScopeTest(unittest.TestCase):
|
|||
global config
|
||||
self.assertTrue('config' not in vars() and 'config' not in globals())
|
||||
self.assertIsNone(fdroidserver.common.config)
|
||||
c = fdroidserver.common.get_config()
|
||||
c = fdroidserver.common.read_config()
|
||||
self.assertIsNotNone(fdroidserver.common.config)
|
||||
self.assertEqual(dict, type(c))
|
||||
self.assertEqual(c, fdroidserver.common.config)
|
||||
|
|
@ -3302,7 +3334,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(CommonTest))
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ if localmodule not in sys.path:
|
|||
import fdroidserver.common
|
||||
import fdroidserver.deploy
|
||||
from fdroidserver.exception import FDroidException
|
||||
from testcommon import TmpCwd, mkdtemp
|
||||
from testcommon import TmpCwd, mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
class DeployTest(unittest.TestCase):
|
||||
|
|
@ -114,11 +114,11 @@ class DeployTest(unittest.TestCase):
|
|||
self.maxDiff = None
|
||||
|
||||
# setup parameters for this test run
|
||||
fdroidserver.deploy.options = mock.Mock()
|
||||
fdroidserver.deploy.options.no_checksum = True
|
||||
fdroidserver.deploy.options.identity_file = None
|
||||
fdroidserver.deploy.options.verbose = False
|
||||
fdroidserver.deploy.options.quiet = True
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
fdroidserver.common.options.no_checksum = True
|
||||
fdroidserver.common.options.identity_file = None
|
||||
fdroidserver.common.options.verbose = False
|
||||
fdroidserver.common.options.quiet = True
|
||||
fdroidserver.deploy.config = {'make_current_version_link': True}
|
||||
url = "example.com:/var/www/fdroid"
|
||||
repo_section = 'repo'
|
||||
|
|
@ -207,12 +207,12 @@ class DeployTest(unittest.TestCase):
|
|||
|
||||
def test_update_serverwebroot_with_id_file(self):
|
||||
# setup parameters for this test run
|
||||
fdroidserver.deploy.options = mock.Mock()
|
||||
fdroidserver.deploy.options.identity_file = None
|
||||
fdroidserver.deploy.options.no_checksum = True
|
||||
fdroidserver.deploy.options.verbose = True
|
||||
fdroidserver.deploy.options.quiet = False
|
||||
fdroidserver.deploy.options.identity_file = None
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
fdroidserver.common.options.identity_file = None
|
||||
fdroidserver.common.options.no_checksum = True
|
||||
fdroidserver.common.options.verbose = True
|
||||
fdroidserver.common.options.quiet = False
|
||||
fdroidserver.common.options.identity_file = None
|
||||
fdroidserver.deploy.config = {'identity_file': './id_rsa'}
|
||||
url = "example.com:/var/www/fdroid"
|
||||
repo_section = 'archive'
|
||||
|
|
@ -289,7 +289,7 @@ class DeployTest(unittest.TestCase):
|
|||
not os.getenv('VIRUSTOTAL_API_KEY'), 'VIRUSTOTAL_API_KEY is not set'
|
||||
)
|
||||
def test_upload_to_virustotal(self):
|
||||
fdroidserver.deploy.options.verbose = True
|
||||
fdroidserver.common.options.verbose = True
|
||||
virustotal_apikey = os.getenv('VIRUSTOTAL_API_KEY')
|
||||
fdroidserver.deploy.upload_to_virustotal('repo', virustotal_apikey)
|
||||
|
||||
|
|
@ -307,12 +307,12 @@ class DeployTest(unittest.TestCase):
|
|||
|
||||
def test_update_servergitmirrors(self):
|
||||
# setup parameters for this test run
|
||||
fdroidserver.deploy.options = mock.Mock()
|
||||
fdroidserver.deploy.options.identity_file = None
|
||||
fdroidserver.deploy.options.no_keep_git_mirror_archive = False
|
||||
fdroidserver.deploy.options.verbose = False
|
||||
fdroidserver.deploy.options.quiet = True
|
||||
fdroidserver.deploy.options.index_only = False
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
fdroidserver.common.options.identity_file = None
|
||||
fdroidserver.common.options.no_keep_git_mirror_archive = False
|
||||
fdroidserver.common.options.verbose = False
|
||||
fdroidserver.common.options.quiet = True
|
||||
fdroidserver.common.options.index_only = False
|
||||
|
||||
config = {}
|
||||
fdroidserver.common.fill_config_defaults(config)
|
||||
|
|
@ -399,7 +399,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(DeployTest))
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ def _build_yaml_representer(dumper, data):
|
|||
parser = ArgumentParser()
|
||||
fdroidserver.common.setup_global_opts(parser)
|
||||
fdroidserver.metadata.add_metadata_arguments(parser)
|
||||
options = parser.parse_args()
|
||||
options = fdroidserver.common.parse_args(parser)
|
||||
fdroidserver.metadata.warnings_action = options.W
|
||||
fdroidserver.common.read_config(None)
|
||||
fdroidserver.common.read_config()
|
||||
|
||||
if not os.path.isdir('metadata'):
|
||||
print("This script must be run in an F-Droid data folder with a 'metadata' subdir!")
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ if __name__ == "__main__":
|
|||
os.chdir(os.path.dirname(__file__))
|
||||
|
||||
import argparse
|
||||
from testcommon import parse_args_for_test
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
|
|
@ -66,8 +67,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.exception.options = parser.parse_args(['--verbose'])
|
||||
fdroidserver.common.options = fdroidserver.exception.options
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(ExceptionTest))
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class GpgsignTest(unittest.TestCase):
|
|||
self.repodir.mkdir()
|
||||
|
||||
gpgsign.config = None
|
||||
config = common.read_config(common.options)
|
||||
config = common.read_config()
|
||||
config['verbose'] = True
|
||||
config['gpghome'] = str((self.basedir / 'gnupghome').resolve())
|
||||
config['gpgkey'] = '1DBA2E89'
|
||||
|
|
@ -84,7 +84,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
common.options = parser.parse_args(['--verbose'])
|
||||
common.parse_args(parser)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(GpgsignTest))
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import fdroidserver.common
|
|||
import fdroidserver.import_subcommand
|
||||
import fdroidserver.metadata
|
||||
from fdroidserver.exception import FDroidException
|
||||
from testcommon import TmpCwd, mkdtemp
|
||||
from testcommon import TmpCwd, mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
class ImportTest(unittest.TestCase):
|
||||
|
|
@ -33,8 +33,6 @@ class ImportTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
self.basedir = localmodule / 'tests'
|
||||
fdroidserver.import_subcommand.options = mock.Mock()
|
||||
fdroidserver.import_subcommand.options.rev = None
|
||||
os.chdir(self.basedir)
|
||||
self._td = mkdtemp()
|
||||
self.testdir = self._td.name
|
||||
|
|
@ -145,7 +143,9 @@ class ImportTest(unittest.TestCase):
|
|||
fdroidserver.import_subcommand.main()
|
||||
|
||||
@mock.patch('sys.argv', ['fdroid import', '-u', 'https://fake/git/url.git'])
|
||||
@mock.patch('fdroidserver.import_subcommand.clone_to_tmp_dir', lambda a: Path('td'))
|
||||
@mock.patch(
|
||||
'fdroidserver.import_subcommand.clone_to_tmp_dir', lambda a, r: Path('td')
|
||||
)
|
||||
def test_main_local_git(self):
|
||||
os.chdir(self.testdir)
|
||||
git.Repo.init('td')
|
||||
|
|
@ -170,7 +170,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(ImportTest))
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ if localmodule not in sys.path:
|
|||
|
||||
import fdroidserver
|
||||
from fdroidserver import common, index, publish, signindex, update
|
||||
from testcommon import TmpCwd, mkdtemp
|
||||
from testcommon import TmpCwd, mkdtemp, parse_args_for_test
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
|
|
@ -55,7 +55,7 @@ class IndexTest(unittest.TestCase):
|
|||
|
||||
common.config = None
|
||||
common.options = Options
|
||||
config = common.read_config(common.options)
|
||||
config = common.read_config()
|
||||
config['jarsigner'] = common.find_sdk_tools_cmd('jarsigner')
|
||||
common.config = config
|
||||
signindex.config = config
|
||||
|
|
@ -751,7 +751,7 @@ class IndexTest(unittest.TestCase):
|
|||
yaml.dump(c, fp)
|
||||
os.system('cat config.yml')
|
||||
common.config = None
|
||||
common.read_config(Options)
|
||||
common.read_config()
|
||||
repodict = {'address': common.config['repo_url']}
|
||||
index.add_mirrors_to_repodict('repo', repodict)
|
||||
self.assertEqual(
|
||||
|
|
@ -951,8 +951,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
options = parser.parse_args(["--verbose"])
|
||||
Options.verbose = options.verbose
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(IndexTest))
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ if localmodule not in sys.path:
|
|||
sys.path.insert(0, localmodule)
|
||||
|
||||
import fdroidserver.init
|
||||
from testcommon import mkdtemp
|
||||
from testcommon import mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
class InitTest(unittest.TestCase):
|
||||
|
|
@ -42,14 +42,14 @@ class InitTest(unittest.TestCase):
|
|||
fp.write('keystore: NONE\n')
|
||||
fp.write('keypass: mysupersecrets\n')
|
||||
os.chmod('config.yml', 0o600)
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
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(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
self.assertIsNone(config.get('keypass'))
|
||||
|
||||
@unittest.skipIf(os.name == 'nt', "calling main() like this hangs on Windows")
|
||||
|
|
@ -84,7 +84,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.init.options = parser.parse_args(['--verbose'])
|
||||
fdroidserver.init.options = parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(InitTest))
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ if __name__ == "__main__":
|
|||
os.chdir(os.path.dirname(__file__))
|
||||
|
||||
import argparse
|
||||
from testcommon import parse_args_for_test
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
|
|
@ -47,8 +48,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.install.options = parser.parse_args(['--verbose'])
|
||||
fdroidserver.common.options = fdroidserver.install.options
|
||||
fdroidserver.install.options = parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(InstallTest))
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ if os.getenv('CI') is None:
|
|||
sys.exit(1)
|
||||
|
||||
os.chdir(os.path.dirname(__file__))
|
||||
config = fdroidserver.common.read_config(common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
nightly.PASSWORD = config['keystorepass']
|
||||
nightly.KEY_ALIAS = config['repo_keyalias']
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import fdroidserver.common
|
|||
import fdroidserver.lint
|
||||
import fdroidserver.metadata
|
||||
from fdroidserver.common import CATEGORIES_CONFIG_NAME
|
||||
from testcommon import mkdtemp
|
||||
from testcommon import mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
class LintTest(unittest.TestCase):
|
||||
|
|
@ -536,8 +536,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.lint.options = parser.parse_args(['--verbose'])
|
||||
fdroidserver.common.options = fdroidserver.lint.options
|
||||
fdroidserver.lint.options = parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(LintTest))
|
||||
|
|
|
|||
|
|
@ -274,7 +274,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
common.options = parser.parse_args(['--verbose'])
|
||||
common.options = common.parse_args(parser)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(MainTest))
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import fdroidserver
|
|||
from fdroidserver import metadata
|
||||
from fdroidserver.exception import MetaDataException
|
||||
from fdroidserver.common import DEFAULT_LOCALE
|
||||
from testcommon import TmpCwd, mkdtemp
|
||||
from testcommon import TmpCwd, mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
def _get_mock_mf(s):
|
||||
|
|
@ -2455,7 +2455,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(MetadataTest))
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
common.options = parser.parse_args(['--verbose'])
|
||||
common.options = common.parse_args(parser)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(NetTest))
|
||||
|
|
|
|||
|
|
@ -373,7 +373,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
common.options = parser.parse_args(['--verbose'])
|
||||
common.options = common.parse_args(parser)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(NightlyTest))
|
||||
|
|
|
|||
13
tests/parse-fdroiddata-mirror-config.py
Normal file
13
tests/parse-fdroiddata-mirror-config.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import ruamel.yaml
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
mirrors_yml = Path('/home/hans/code/fdroid/fdroiddata/config/mirrors.yml')
|
||||
with mirrors_yml.open() as fp:
|
||||
mirrors_config = ruamel.yaml.YAML(typ='safe').load(fp)
|
||||
|
||||
for d in mirrors_config:
|
||||
d['url'] += '/repo'
|
||||
print(d, end=',\n')
|
||||
|
|
@ -33,7 +33,7 @@ from fdroidserver import common
|
|||
from fdroidserver import metadata
|
||||
from fdroidserver import signatures
|
||||
from fdroidserver.exception import FDroidException
|
||||
from testcommon import mkdtemp
|
||||
from testcommon import mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
class PublishTest(unittest.TestCase):
|
||||
|
|
@ -266,7 +266,8 @@ class PublishTest(unittest.TestCase):
|
|||
|
||||
os.chdir(self.testdir)
|
||||
|
||||
config = common.read_config(Options)
|
||||
common.options = Options
|
||||
config = common.read_config()
|
||||
if 'apksigner' not in config:
|
||||
self.skipTest('SKIPPING test_sign_then_implant_signature, apksigner not installed!')
|
||||
config['repo_keyalias'] = 'sova'
|
||||
|
|
@ -340,7 +341,8 @@ class PublishTest(unittest.TestCase):
|
|||
|
||||
os.chdir(self.testdir)
|
||||
|
||||
config = common.read_config(Options)
|
||||
common.options = Options
|
||||
config = common.read_config()
|
||||
if 'apksigner' not in config:
|
||||
self.skipTest('SKIPPING test_error_on_failed, apksigner not installed!')
|
||||
config['repo_keyalias'] = 'sova'
|
||||
|
|
@ -422,7 +424,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(PublishTest))
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
common.options = parser.parse_args(['--verbose'])
|
||||
common.options = common.parse_args(parser)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(RewriteMetaTest))
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import fdroidserver.build
|
|||
import fdroidserver.common
|
||||
import fdroidserver.metadata
|
||||
import fdroidserver.scanner
|
||||
from testcommon import TmpCwd, mkdtemp, mock_open_to_str
|
||||
from testcommon import TmpCwd, mkdtemp, mock_open_to_str, parse_args_for_test
|
||||
|
||||
|
||||
class ScannerTest(unittest.TestCase):
|
||||
|
|
@ -46,8 +46,8 @@ class ScannerTest(unittest.TestCase):
|
|||
self._td.cleanup()
|
||||
|
||||
def test_scan_source_files(self):
|
||||
fdroidserver.scanner.options = mock.Mock()
|
||||
fdroidserver.scanner.options.json = False
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
fdroidserver.common.options.json = False
|
||||
source_files = os.path.join(self.basedir, 'source-files')
|
||||
projects = {
|
||||
'OtakuWorld': 2,
|
||||
|
|
@ -102,8 +102,8 @@ class ScannerTest(unittest.TestCase):
|
|||
"""Check for sneaking in banned maven repos"""
|
||||
os.chdir(self.testdir)
|
||||
fdroidserver.scanner.config = None
|
||||
fdroidserver.scanner.options = mock.Mock()
|
||||
fdroidserver.scanner.options.json = True
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
fdroidserver.common.options.json = True
|
||||
with open('build.gradle', 'w', encoding='utf-8') as fp:
|
||||
fp.write(
|
||||
textwrap.dedent(
|
||||
|
|
@ -135,8 +135,8 @@ class ScannerTest(unittest.TestCase):
|
|||
os.chdir(abs_build_dir)
|
||||
|
||||
fdroidserver.scanner.config = None
|
||||
fdroidserver.scanner.options = mock.Mock()
|
||||
fdroidserver.scanner.options.json = True
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
fdroidserver.common.options.json = True
|
||||
|
||||
keep = [
|
||||
'arg.jar',
|
||||
|
|
@ -235,7 +235,7 @@ class ScannerTest(unittest.TestCase):
|
|||
fdroidserver.build.options.scan_binary = False
|
||||
fdroidserver.build.options.notarball = True
|
||||
fdroidserver.build.options.skipscan = False
|
||||
fdroidserver.scanner.options = fdroidserver.build.options
|
||||
fdroidserver.common.options = fdroidserver.build.options
|
||||
|
||||
app = fdroidserver.metadata.App()
|
||||
app.id = 'mocked.app.id'
|
||||
|
|
@ -314,7 +314,7 @@ class ScannerTest(unittest.TestCase):
|
|||
"""Check that the scanner can handle scandelete with gradle files with multiple problems"""
|
||||
os.chdir(self.testdir)
|
||||
fdroidserver.scanner.config = None
|
||||
fdroidserver.scanner.options = mock.Mock()
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
build = fdroidserver.metadata.Build()
|
||||
build.scandelete = ['build.gradle']
|
||||
with open('build.gradle', 'w', encoding='utf-8') as fp:
|
||||
|
|
@ -732,15 +732,15 @@ class Test_ScannerTool(unittest.TestCase):
|
|||
refresh.assert_not_called()
|
||||
|
||||
def test_refresh_true(self):
|
||||
fdroidserver.scanner.options = mock.Mock()
|
||||
fdroidserver.scanner.options.refresh_scanner = True
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
fdroidserver.common.options.refresh_scanner = True
|
||||
with mock.patch('fdroidserver.scanner.ScannerTool.refresh') as refresh:
|
||||
fdroidserver.scanner.ScannerTool()
|
||||
refresh.assert_called_once()
|
||||
|
||||
def test_refresh_false(self):
|
||||
fdroidserver.scanner.options = mock.Mock()
|
||||
fdroidserver.scanner.options.refresh_scanner = False
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
fdroidserver.common.options.refresh_scanner = False
|
||||
with mock.patch('fdroidserver.scanner.ScannerTool.refresh') as refresh:
|
||||
fdroidserver.scanner.ScannerTool()
|
||||
refresh.assert_not_called()
|
||||
|
|
@ -753,8 +753,8 @@ class Test_ScannerTool(unittest.TestCase):
|
|||
refresh.assert_called_once()
|
||||
|
||||
def test_refresh_options_overrides_config(self):
|
||||
fdroidserver.scanner.options = mock.Mock()
|
||||
fdroidserver.scanner.options.refresh_scanner = True
|
||||
fdroidserver.common.options = mock.Mock()
|
||||
fdroidserver.common.options.refresh_scanner = True
|
||||
os.chdir(self.testdir)
|
||||
pathlib.Path('config.yml').write_text('refresh_scanner: false')
|
||||
with mock.patch('fdroidserver.scanner.ScannerTool.refresh') as refresh:
|
||||
|
|
@ -824,7 +824,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTests(
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class SignaturesTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
common.config = None
|
||||
config = common.read_config(common.options)
|
||||
config = common.read_config()
|
||||
config['jarsigner'] = common.find_sdk_tools_cmd('jarsigner')
|
||||
config['verbose'] = True
|
||||
common.config = config
|
||||
|
|
@ -68,7 +68,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
common.options = parser.parse_args(['--verbose'])
|
||||
common.options = common.parse_args(parser)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(SignaturesTest))
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class SignindexTest(unittest.TestCase):
|
|||
|
||||
def setUp(self):
|
||||
signindex.config = None
|
||||
config = common.read_config(common.options)
|
||||
config = common.read_config()
|
||||
config['jarsigner'] = common.find_sdk_tools_cmd('jarsigner')
|
||||
config['verbose'] = True
|
||||
config['keystore'] = str(self.basedir / 'keystore.jks')
|
||||
|
|
@ -202,7 +202,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
common.options = parser.parse_args(['--verbose'])
|
||||
common.options = common.parse_args(parser)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(SignindexTest))
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import tempfile
|
|||
import unittest
|
||||
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
|
||||
class TmpCwd:
|
||||
|
|
@ -72,3 +73,16 @@ def mkdir_testfiles(localmodule, test):
|
|||
testdir = testroot / unittest.TestCase.id(test)
|
||||
testdir.mkdir(exist_ok=True)
|
||||
return tempfile.mkdtemp(dir=testdir)
|
||||
|
||||
|
||||
def parse_args_for_test(parser, args):
|
||||
"""Only send --flags to the ArgumentParser, not test classes, etc."""
|
||||
|
||||
from fdroidserver.common import parse_args
|
||||
|
||||
flags = []
|
||||
for arg in args:
|
||||
if arg[0] == '-':
|
||||
flags.append(flags)
|
||||
with mock.patch('sys.argv', flags):
|
||||
parse_args(parser)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ import fdroidserver.metadata
|
|||
import fdroidserver.update
|
||||
from fdroidserver.common import CATEGORIES_CONFIG_NAME
|
||||
from fdroidserver.looseversion import LooseVersion
|
||||
from testcommon import TmpCwd, mkdtemp
|
||||
from testcommon import TmpCwd, mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
DONATION_FIELDS = ('Donate', 'Liberapay', 'OpenCollective')
|
||||
|
|
@ -1207,7 +1207,7 @@ class UpdateTest(unittest.TestCase):
|
|||
|
||||
# Set up options
|
||||
fdroidserver.common.options = Options
|
||||
config = fdroidserver.common.read_config(fdroidserver.common.options)
|
||||
config = fdroidserver.common.read_config()
|
||||
if 'apksigner' not in config: # TODO remove me for buildserver-bullseye
|
||||
self.skipTest('SKIPPING test_update_with_AllowedAPKSigningKeys, apksigner not installed!')
|
||||
config['repo_keyalias'] = 'sova'
|
||||
|
|
@ -2280,7 +2280,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(UpdateTest))
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import fdroidserver.build
|
|||
import fdroidserver.common
|
||||
import fdroidserver.metadata
|
||||
import fdroidserver.scanner
|
||||
from testcommon import mkdtemp
|
||||
from testcommon import mkdtemp, parse_args_for_test
|
||||
|
||||
|
||||
class VCSTest(unittest.TestCase):
|
||||
|
|
@ -97,7 +97,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
fdroidserver.common.options = parser.parse_args(['--verbose'])
|
||||
parse_args_for_test(parser, sys.argv)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(VCSTest))
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ if __name__ == "__main__":
|
|||
default=False,
|
||||
help="Spew out even more information than normal",
|
||||
)
|
||||
common.options = parser.parse_args(['--verbose'])
|
||||
common.options = common.parse_args(parser)
|
||||
|
||||
newSuite = unittest.TestSuite()
|
||||
newSuite.addTest(unittest.makeSuite(VerifyTest))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue