def test_find_database_by_pattern_none(self, mock_redis): ctx = mock_redis.return_value ctx.keys.return_value = None new_ctx, index = OpenvasDB.find_database_by_pattern('foo*', 123) self.assertIsNone(new_ctx) self.assertIsNone(index)
def test_find_database_by_pattern(self, mock_redis): ctx = mock_redis.return_value # keys is called twice per iteration ctx.keys.side_effect = [None, None, None, None, True, True] new_ctx, index = OpenvasDB.find_database_by_pattern('foo*', 123) self.assertEqual(new_ctx, ctx) self.assertEqual(index, 2)
def ctx(self) -> Optional[RedisCtx]: if self._ctx is None: self._ctx, self.index = OpenvasDB.find_database_by_pattern( NVTI_CACHE_NAME, self._main_db.max_database_index) return self._ctx
def ctx(self) -> Optional[RedisCtx]: if self._ctx is None: self._ctx, self.index = OpenvasDB.find_database_by_pattern( self._get_nvti_cache_name(), self._main_db.max_database_index) return self._ctx