def test_is_enough_cached_data_present(cache_manager: CacheManager): cache_entries = [f'{{"timestamp": {get_utc_now()}}}'] * 1 with mock.patch( "cache.cache_manager.read_cached_values_by_feature") as read_cache: read_cache.return_value = cache_entries assert (cache_manager.is_enough_cached_data_present(ACCESSIBILITY) is False) cache_entries = [f'{{"timestamp": {get_utc_now()}}}'] * 5 with mock.patch( "cache.cache_manager.read_cached_values_by_feature") as read_cache: read_cache.return_value = cache_entries assert (cache_manager.is_enough_cached_data_present(ACCESSIBILITY) is True)
async def _extract_meta_data( self, allow_list: dict, cache_manager: CacheManager, shared_memory_name: str, ) -> dict: data = {} tasks = [] shared_status = shared_memory.ShareableList(name=shared_memory_name) shared_status[0] = 0 for metadata_extractor in self.metadata_extractors: if allow_list[metadata_extractor.key]: if (not cache_manager.bypass and self.is_feature_whitelisted_for_cache( metadata_extractor) and cache_manager.is_host_predefined() and cache_manager.is_enough_cached_data_present( metadata_extractor.key)): extracted_metadata: dict = ( cache_manager.get_predefined_metadata( metadata_extractor.key)) data.update(extracted_metadata) shared_status[0] += 1 else: tasks.append(metadata_extractor.start()) extracted_metadata: tuple[dict] = await asyncio.gather(*tasks) shared_status[0] += len(tasks) data = {**data, **dict(ChainMap(*extracted_metadata))} return data