def _get_skill_opportunities_with_corresponding_topic_name(self, cursor): """Returns a list of skill opportunities available for questions with topic information. Args: cursor: str or None. If provided, the list of returned entities starts from this datastore cursor. Otherwise, the returned entities start from the beginning of the full list of entities. Returns: 3-tuple(opportunities, cursor, more). where: opportunities: list(dict). A list of dicts of skill opportunity details with additional corresponding topic_name. cursor: str or None. A query cursor pointing to the next batch of results. If there are no more results, this might be None. more: bool. If True, there are (probably) more results after this batch. If False, there are no further results after this batch. """ topics_with_skills = topic_fetchers.get_all_topics_with_skills() skill_opportunities, cursor, more = ( opportunity_services.get_skill_opportunities(cursor)) id_to_skill_opportunity_dict = { opp.id: opp.to_dict() for opp in skill_opportunities } opportunities = [] for topic in topics_with_skills: for skill_id in topic.get_all_skill_ids(): if len(opportunities) == feconf.OPPORTUNITIES_PAGE_SIZE: break if skill_id in id_to_skill_opportunity_dict: skill_opportunity_dict = ( id_to_skill_opportunity_dict[skill_id]) skill_opportunity_dict['topic_name'] = topic.name opportunities.append(skill_opportunity_dict) return opportunities, cursor, more
def test_get_all_topics_with_skills(self): expected_topic = self.topic.to_dict() topics = topic_fetchers.get_all_topics_with_skills() self.assertEqual(topics[0].to_dict(), expected_topic) self.assertEqual(len(topics), 1)