mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-08-16 19:30:09 +02:00
scanner: add refresh_config config item for buildserver
Includes some cosmetic changes from black.
This commit is contained in:
parent
907dfd1c3c
commit
031a130395
@ -373,3 +373,9 @@
|
||||
# - suss
|
||||
# - exodus
|
||||
# - https://example.com/signatures.json
|
||||
|
||||
# The scanner can use signature sources from the internet. These are
|
||||
# cached locally. To force them to be refreshed from the network on
|
||||
# every run, set this to true:
|
||||
#
|
||||
# refresh_scanner: true
|
||||
|
@ -325,15 +325,15 @@ class SUSSDataController(SignatureDataController):
|
||||
self.set_data(json.loads(SUSS_DEFAULT))
|
||||
|
||||
|
||||
class ScannerTool():
|
||||
class ScannerTool:
|
||||
def __init__(self):
|
||||
|
||||
# we could add support for loading additional signature source
|
||||
# definitions from config.yml here
|
||||
|
||||
self.scanner_data_lookup()
|
||||
|
||||
if options and options.refresh_scanner:
|
||||
config = common.get_config()
|
||||
if (options and options.refresh_scanner) or config.get('refresh_scanner'):
|
||||
self.refresh()
|
||||
|
||||
self.load()
|
||||
|
@ -704,6 +704,20 @@ class Test_SignatureDataController(unittest.TestCase):
|
||||
|
||||
|
||||
class Test_ScannerTool(unittest.TestCase):
|
||||
def setUp(self):
|
||||
fdroidserver.common.options = None
|
||||
fdroidserver.common.config = None
|
||||
self.basedir = os.path.join(localmodule, 'tests')
|
||||
os.chdir(self.basedir)
|
||||
self._td = mkdtemp()
|
||||
self.testdir = self._td.name
|
||||
|
||||
def tearDown(self):
|
||||
fdroidserver.common.options = None
|
||||
fdroidserver.common.config = None
|
||||
os.chdir(self.basedir)
|
||||
self._td.cleanup()
|
||||
|
||||
def test_load(self):
|
||||
st = mock.Mock()
|
||||
st.sdcs = [mock.Mock(), mock.Mock()]
|
||||
@ -711,7 +725,8 @@ class Test_ScannerTool(unittest.TestCase):
|
||||
st.sdcs[0].load.assert_called_once_with()
|
||||
st.sdcs[1].load.assert_called_once_with()
|
||||
|
||||
def test_refresh_default(self):
|
||||
def test_refresh_no_options_or_config(self):
|
||||
"""This simulates what happens when running something like scan_source()"""
|
||||
with mock.patch('fdroidserver.scanner.ScannerTool.refresh') as refresh:
|
||||
fdroidserver.scanner.ScannerTool()
|
||||
refresh.assert_not_called()
|
||||
@ -730,6 +745,22 @@ class Test_ScannerTool(unittest.TestCase):
|
||||
fdroidserver.scanner.ScannerTool()
|
||||
refresh.assert_not_called()
|
||||
|
||||
def test_refresh_from_config(self):
|
||||
os.chdir(self.testdir)
|
||||
pathlib.Path('config.yml').write_text('refresh_scanner: true')
|
||||
with mock.patch('fdroidserver.scanner.ScannerTool.refresh') as refresh:
|
||||
fdroidserver.scanner.ScannerTool()
|
||||
refresh.assert_called_once()
|
||||
|
||||
def test_refresh_options_overrides_config(self):
|
||||
fdroidserver.scanner.options = mock.Mock()
|
||||
fdroidserver.scanner.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:
|
||||
fdroidserver.scanner.ScannerTool()
|
||||
refresh.assert_called_once()
|
||||
|
||||
|
||||
class Test_main(unittest.TestCase):
|
||||
def setUp(self):
|
||||
|
Loading…
Reference in New Issue
Block a user