def test_mark_scanner_index_complete_no_failures(self, mock_date_time): start = datetime.utcnow() end = start + timedelta(minutes=5) mock_date_time.side_effect = [start, end] scanner_index_id = scanner.init_scanner_index(self.session, self.inv_index_id2) scanner.mark_scanner_index_complete(self.session, scanner_index_id, ['IamPolicyScanner'], []) db_row = (self.session.query(scanner_dao.ScannerIndex).filter( scanner_dao.ScannerIndex.id == scanner_index_id).one()) self.assertEquals(IndexState.SUCCESS, db_row.scanner_status) self.assertEquals(end, db_row.completed_at_datetime)
def test_mark_scanner_index_complete_only_failures(self, mock_date_time): start = datetime.utcnow() end = start + timedelta(minutes=5) mock_date_time.side_effect = [start, end] scanner_index_id = scanner.init_scanner_index(self.session, self.inv_index_id2) scanner.mark_scanner_index_complete(self.session, scanner_index_id, [], ['IamPolicyScanner', 'IapScanner']) db_row = (self.session.query(scanner_dao.ScannerIndex).filter( scanner_dao.ScannerIndex.id == scanner_index_id).one()) self.assertEqual(IndexState.FAILURE, db_row.scanner_status) self.assertEqual( 'Scanner(s) with errors: IamPolicyScanner, IapScanner', db_row.scanner_index_errors) self.assertEqual(end, db_row.completed_at_datetime)
def populate_db(self, violations=FAKE_VIOLATIONS, inv_index_id=FAKE_INV_INDEX_ID, scanner_index_id=None, succeeded=['IamPolicyScanner'], failed=[]): """Populate the db with violations. Args: violations (dict): the violations to write to the test database inv_index_id (str): the inventory index to use scanner_index_id (str): the scanner index to use succeeded (list): names of scanners that ran successfully failed (list): names of scanners that failed """ if not scanner_index_id: scanner_index_id = scanner.init_scanner_index( self.session, inv_index_id) self.violation_access.create(violations, scanner_index_id) scanner.mark_scanner_index_complete(self.session, scanner_index_id, succeeded, failed) return scanner_index_id