def _get_target_id_to_skill_opportunity_dict(suggestions): """Returns a dict of target_id to skill opportunity summary dict. Args: suggestions: list(BaseSuggestion). A list of suggestions to retrieve opportunity dicts. Returns: dict. Dict mapping target_id to corresponding skill opportunity dict. """ target_ids = set([s.target_id for s in suggestions]) opportunity_id_to_opportunity_dict = { opp_id: (opp.to_dict() if opp is not None else None) for opp_id, opp in opportunity_services.get_skill_opportunities_by_ids( list(target_ids)).items() } opportunity_id_to_skill = { skill.id: skill for skill in skill_fetchers.get_multi_skills([ opp['id'] for opp in opportunity_id_to_opportunity_dict.values() if opp is not None ]) } for opp_id, skill in opportunity_id_to_skill.items(): if skill is not None: opportunity_id_to_opportunity_dict[opp_id]['skill_rubrics'] = [ rubric.to_dict() for rubric in skill.rubrics ] return opportunity_id_to_opportunity_dict
def _get_target_id_to_skill_opportunity_dict(suggestions): """Returns a dict of target_id to skill opportunity summary dict. Args: suggestions: list(BaseSuggestion). A list of suggestions to retrieve opportunity dicts. Returns: dict. Dict mapping target_id to corresponding skill opportunity dict. """ target_ids = set([s.target_id for s in suggestions]) opportunities = (opportunity_services.get_skill_opportunities_by_ids( list(target_ids))) opportunity_skill_ids = [opp.id for opp in opportunities] opportunity_id_to_skill = { skill.id: skill for skill in skill_services.get_multi_skills(opportunity_skill_ids) } opportunity_id_to_opportunity = {} for opp in opportunities: opp_dict = opp.to_dict() skill = opportunity_id_to_skill.get(opp.id) if skill is not None: opp_dict['skill_rubrics'] = [ rubric.to_dict() for rubric in skill.rubrics ] opportunity_id_to_opportunity[opp.id] = opp_dict return opportunity_id_to_opportunity
def test_get_skill_opportunities_by_ids_if_returns_empty_list(self): get_multi_swap = self.swap(opportunity_models.SkillOpportunityModel, 'get_multi', self._mock_get_multi_function) with get_multi_swap: opportunities = ( opportunity_services.get_skill_opportunities_by_ids(['0'])) self.assertEqual(len(opportunities), 0)
def _get_target_id_to_skill_opportunity_dict(suggestions): """Returns a dict of target_id to skill opportunity summary dict. Args: suggestions: list(BaseSuggestion). A list of suggestions to retrieve opportunity dicts. Returns: dict. Dict mapping target_id to corresponding skill opportunity dict. """ target_ids = set([s.target_id for s in suggestions]) opportunities = ( opportunity_services.get_skill_opportunities_by_ids(list(target_ids))) return {opp.id: opp.to_dict() for opp in opportunities}