Exemplo n.º 1
0
    def test_delete_question_skill_link_decrements_question_count(self):
        opportunity_services.create_skill_opportunity(
            self.SKILL_ID, 'description')
        self.save_new_question(
            self.QUESTION_ID, self.USER_ID,
            self._create_valid_question_data('ABC'), ['skill_2'])
        question_services.create_new_question_skill_link(
            self.USER_ID, self.QUESTION_ID, self.SKILL_ID, 0.3)

        question_services.delete_question_skill_link(
            self.USER_ID, self.QUESTION_ID, self.SKILL_ID)

        skill_opportunities, _, _ = (
            opportunity_services.get_skill_opportunities(None))
        opportunity = skill_opportunities[0]
        self.assertEqual(opportunity.question_count, 0)
Exemplo n.º 2
0
    def test_create_skill_opportunity_counts_existing_linked_questions(self):
        self.save_new_question(self.QUESTION_ID, self.USER_ID,
                               self._create_valid_question_data('ABC'),
                               [self.SKILL_ID])
        question_services.create_new_question_skill_link(
            self.USER_ID, self.QUESTION_ID, self.SKILL_ID, 0.3)

        opportunity_services.create_skill_opportunity(self.SKILL_ID,
                                                      'description')

        skill_opportunities, _, _ = (
            opportunity_services.get_skill_opportunities(None))
        self.assertEqual(len(skill_opportunities), 1)
        opportunity = skill_opportunities[0]
        self.assertEqual(opportunity.id, self.SKILL_ID)
        self.assertEqual(opportunity.skill_description, 'description')
        self.assertEqual(opportunity.question_count, 1)
Exemplo n.º 3
0
    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.
        """
        # We want to focus attention on lessons that are part of a classroom.
        # See issue #12221.
        classroom_topic_ids = []
        for classroom_dict in config_domain.CLASSROOM_PAGES_DATA.value:
            classroom_topic_ids.extend(classroom_dict['topic_ids'])
        classroom_topics = topic_fetchers.get_topics_by_ids(classroom_topic_ids)
        classroom_topics_with_skills = [
            topic for topic in classroom_topics
            if topic and topic.get_all_skill_ids()
        ]
        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 classroom_topics_with_skills:
            for skill_id in topic.get_all_skill_ids():
                if len(opportunities) == constants.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_update_skill_description_updates_skill_opportunity(self):
        self.save_new_skill(self.SKILL_ID, self.USER_ID, 'skill_description')
        changelist = [
            skill_domain.SkillChange({
                'cmd': skill_domain.CMD_UPDATE_SKILL_PROPERTY,
                'property_name': (
                    skill_domain.SKILL_PROPERTY_DESCRIPTION),
                'old_value': 'skill_description',
                'new_value': 'new_description'
            })
        ]

        skill_services.update_skill(
            self.admin_id, self.SKILL_ID, changelist,
            'Updated misconception name.')

        skill_opportunities, _, _ = (
            opportunity_services.get_skill_opportunities(None))
        opportunity = skill_opportunities[0]
        self.assertEqual(opportunity['id'], self.SKILL_ID)
        self.assertEqual(opportunity['skill_description'], 'new_description')
Exemplo n.º 5
0
    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