Make security scan testing much faster

This commit is contained in:
Joseph Schorr 2016-05-05 13:55:24 -04:00
parent 836a99083e
commit 343a080833
4 changed files with 13 additions and 5 deletions

View file

@ -10,6 +10,7 @@ from util.secscan.api import SecurityScannerAPI, AnalyzeLayerException
from util.secscan.analyzer import LayerAnalyzer
from util.secscan.notifier import process_notification_data
from data import model
from storage.basestorage import StoragePaths
from workers.security_notification_worker import SecurityNotificationWorker
from endpoints.v2 import v2_bp
@ -116,9 +117,11 @@ class TestSecurityScanner(unittest.TestCase):
# Enable direct download in fake storage.
storage.put_content(['local_us'], 'supports_direct_download', 'true')
# Have fake storage say all files exist for the duration of the test.
storage.put_content(['local_us'], 'all_files_exist', 'true')
# Setup the database with fake storage.
force_rebuild = os.environ.get('SKIP_REBUILD') != 'true'
setup_database_for_testing(self, with_storage=True, force_rebuild=force_rebuild)
setup_database_for_testing(self)
self.app = app.test_client()
self.ctx = app.test_request_context()
self.ctx.__enter__()
@ -126,7 +129,9 @@ class TestSecurityScanner(unittest.TestCase):
self.api = SecurityScannerAPI(app, app.config, storage)
def tearDown(self):
storage.put_content(['local_us'], 'supports_direct_download', 'false')
storage.remove(['local_us'], 'supports_direct_download')
storage.remove(['local_us'], 'all_files_exist')
finished_database_for_testing(self)
self.ctx.__exit__(True, None, None)
@ -256,6 +261,7 @@ class TestSecurityScanner(unittest.TestCase):
path = model.storage.get_layer_path(layer.storage)
locations = app.config['DISTRIBUTED_STORAGE_PREFERENCE']
storage.remove(locations, path)
storage.remove(locations, 'all_files_exist')
with HTTMock(analyze_layer_success_mock, response_content):
analyzer = LayerAnalyzer(app.config, self.api)