Example #1
0
    def test_mark_story_and_topic_as_completed_and_learnt(self):
        csrf_token = self.get_new_csrf_token()
        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID)
        self.assertEqual(
            len(
                learner_goals_services.get_all_topic_ids_to_learn(
                    self.viewer_id)), 1)
        story_services.record_completed_node_in_story_context(
            self.viewer_id, self.STORY_ID, self.NODE_ID_2)
        story_services.record_completed_node_in_story_context(
            self.viewer_id, self.STORY_ID, self.NODE_ID_1)
        with self.swap(constants, 'ENABLE_NEW_STRUCTURE_VIEWER_UPDATES', True):
            self.post_json('%s/staging/topic/%s/%s' %
                           (feconf.STORY_PROGRESS_URL_PREFIX,
                            self.STORY_URL_FRAGMENT, self.NODE_ID_3), {},
                           csrf_token=csrf_token)

        self.assertEqual(
            len(
                learner_progress_services.get_all_learnt_topic_ids(
                    self.viewer_id)), 1)
        self.assertEqual(
            len(
                learner_goals_services.get_all_topic_ids_to_learn(
                    self.viewer_id)), 0)
        self.assertEqual(
            len(
                learner_progress_services.get_all_completed_story_ids(
                    self.viewer_id)), 1)
    def test_can_see_topics_to_learn(self):
        self.login(self.VIEWER_EMAIL)

        response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL)
        self.assertEqual(len(response['topics_to_learn_list']), 0)

        self.save_new_topic(self.TOPIC_ID_1,
                            self.owner_id,
                            name=self.TOPIC_NAME_1,
                            url_fragment='topic-one',
                            description='A new topic',
                            canonical_story_ids=[],
                            additional_story_ids=[],
                            uncategorized_skill_ids=[],
                            subtopics=[self.subtopic_0],
                            next_subtopic_id=1)
        topic_services.publish_topic(self.TOPIC_ID_1, self.admin_id)
        self.save_new_story(self.STORY_ID_2, self.owner_id, self.TOPIC_ID_1)
        topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_1,
                                           self.STORY_ID_2)
        topic_services.publish_story(self.TOPIC_ID_1, self.STORY_ID_2,
                                     self.admin_id)

        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID_1)
        response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL)
        self.assertEqual(len(response['topics_to_learn_list']), 1)
        self.assertEqual(response['topics_to_learn_list'][0]['id'],
                         self.TOPIC_ID_1)
        self.logout()
 def test_single_topic_is_added_correctly_to_learn(self):
     # Test adding a single topic_id to learn.
     self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [])
     learner_progress_services.validate_and_add_topic_to_learn_goal(
         self.viewer_id, self.TOPIC_ID_1)
     self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                      [self.TOPIC_ID_1])
    def test_completed_topic_is_not_added_to_learner_goals(self):
        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID_1)
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                         [self.TOPIC_ID_1])

        learner_progress_services.mark_topic_as_learnt(self.viewer_id,
                                                       self.TOPIC_ID_2)

        # Test that the topic added to the in the learnt list doesn't get
        # added to the learner goals.
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                         [self.TOPIC_ID_1])
    def test_multiple_topics_are_added_correctly_to_learn(self):
        # Test adding two topics to the learn.
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [])

        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID_1)
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                         [self.TOPIC_ID_1])

        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID_2)
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                         [self.TOPIC_ID_1, self.TOPIC_ID_2])
Example #6
0
    def test_remove_topic_from_learner_goals(self):
        self.login(self.VIEWER_EMAIL)
        csrf_token = self.get_new_csrf_token()

        # Add topic to the learner goals.
        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID_1)
        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID_2)
        self.assertEqual(
            learner_goals_services.get_all_topic_ids_to_learn(
                self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2])

        # Remove an topic.
        self.delete_json(
            '%s/%s/%s' % (
                feconf.LEARNER_GOALS_DATA_URL,
                constants.ACTIVITY_TYPE_LEARN_TOPIC,
                self.TOPIC_ID_1))
        self.assertEqual(
            learner_goals_services.get_all_topic_ids_to_learn(
                self.viewer_id), [self.TOPIC_ID_2])

        # Remove the second topic.
        self.delete_json('%s/%s/%s' % (
            feconf.LEARNER_GOALS_DATA_URL,
            constants.ACTIVITY_TYPE_LEARN_TOPIC,
            self.TOPIC_ID_2))
        self.assertEqual(
            learner_goals_services.get_all_topic_ids_to_learn(
                self.viewer_id), [])

        # Add one topic to the learner goal.
        self.post_json(
            '%s/%s/%s' % (
                feconf.LEARNER_GOALS_DATA_URL,
                constants.ACTIVITY_TYPE_LEARN_TOPIC,
                self.TOPIC_ID_1), {},
            csrf_token=csrf_token)

        # Fail to delete one topic from learner goals.
        response = self.delete_json('%s/%s/%s' % (
            feconf.LEARNER_GOALS_DATA_URL,
            'InvalidActivityType',
            self.TOPIC_ID_1), expected_status_int=400)
        self.assertEqual(
            response['error'], 'Invalid activityType: InvalidActivityType')

        self.logout()
    def test_number_of_topics_cannot_exceed_max(self):
        # Add MAX_CURRENT_GOALS_COUNT topics.
        topic_ids = [
            'SAMPLE_TOPIC_ID_%s' % index
            for index in (python_utils.RANGE(0, MAX_CURRENT_GOALS_COUNT))
        ]
        for topic_id in topic_ids:
            learner_progress_services.validate_and_add_topic_to_learn_goal(
                self.viewer_id, topic_id)
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                         topic_ids)

        # Now if we try to add another topic at the end of the list,
        # it shouldn't be added as the list length would exceed
        # MAX_CURRENT_GOALS_COUNT.
        learner_goals_services.mark_topic_to_learn(self.viewer_id,
                                                   'SAMPLE_TOPIC_ID_MAX')
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                         topic_ids)
Example #8
0
    def post(self, activity_type, topic_id):
        belongs_to_learnt_list = False
        goals_limit_exceeded = False

        if activity_type == constants.ACTIVITY_TYPE_LEARN_TOPIC:
            belongs_to_learnt_list, goals_limit_exceeded = (
                learner_progress_services.validate_and_add_topic_to_learn_goal(
                    self.user_id, topic_id))
        else:
            raise self.InvalidInputException('Invalid activityType: %s' %
                                             (activity_type))

        self.values.update({
            'belongs_to_learnt_list': belongs_to_learnt_list,
            'goals_limit_exceeded': goals_limit_exceeded
        })

        self.render_json(self.values)
    def test_adding_exisiting_topic_is_not_added_again(self):
        # Test adding the topic_id if it is already in
        # learner_goals.topic_id.
        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID_1)
        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID_2)
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                         [self.TOPIC_ID_1, self.TOPIC_ID_2])

        with self.assertRaisesRegexp(
                Exception,
                'The topic id Topic_id_1 is already present in the learner goals'
        ):
            learner_progress_services.validate_and_add_topic_to_learn_goal(
                self.viewer_id, self.TOPIC_ID_1)
    def test_get_learner_dashboard_ids(self):
        self.login(self.VIEWER_EMAIL)

        self.save_new_default_exploration(self.EXP_ID_1,
                                          self.owner_id,
                                          title=self.EXP_TITLE_1)
        self.publish_exploration(self.owner_id, self.EXP_ID_1)
        self.save_new_default_exploration(self.EXP_ID_2,
                                          self.owner_id,
                                          title=self.EXP_TITLE_2)
        self.publish_exploration(self.owner_id, self.EXP_ID_2)
        self.save_new_default_exploration(self.EXP_ID_3,
                                          self.owner_id,
                                          title=self.EXP_TITLE_3)
        self.publish_exploration(self.owner_id, self.EXP_ID_3)

        self.save_new_default_collection(self.COL_ID_1,
                                         self.owner_id,
                                         title=self.COL_TITLE_1)
        self.publish_collection(self.owner_id, self.COL_ID_1)
        self.save_new_default_collection(self.COL_ID_2,
                                         self.owner_id,
                                         title=self.COL_TITLE_2)
        self.publish_collection(self.owner_id, self.COL_ID_2)
        self.save_new_default_collection(self.COL_ID_3,
                                         self.owner_id,
                                         title=self.COL_TITLE_3)
        self.publish_collection(self.owner_id, self.COL_ID_3)

        self.save_new_topic(self.TOPIC_ID_1,
                            self.owner_id,
                            name=self.TOPIC_NAME_1,
                            url_fragment='topic-one',
                            description='A new topic',
                            canonical_story_ids=[],
                            additional_story_ids=[],
                            uncategorized_skill_ids=[],
                            subtopics=[self.subtopic_0],
                            next_subtopic_id=1)
        self.save_new_story(self.STORY_ID_1, self.owner_id, self.TOPIC_ID_1)
        topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_1,
                                           self.STORY_ID_1)

        topic_services.publish_story(self.TOPIC_ID_1, self.STORY_ID_1,
                                     self.admin_id)
        topic_services.publish_topic(self.TOPIC_ID_1, self.admin_id)

        self.save_new_topic(self.TOPIC_ID_2,
                            self.owner_id,
                            name=self.TOPIC_NAME_2,
                            url_fragment='topic-two',
                            description='A new topic',
                            canonical_story_ids=[],
                            additional_story_ids=[],
                            uncategorized_skill_ids=[],
                            subtopics=[self.subtopic_1],
                            next_subtopic_id=1)
        self.save_new_story(self.STORY_ID_2, self.owner_id, self.TOPIC_ID_2)
        topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_2,
                                           self.STORY_ID_2)

        topic_services.publish_story(self.TOPIC_ID_2, self.STORY_ID_2,
                                     self.admin_id)
        topic_services.publish_topic(self.TOPIC_ID_2, self.admin_id)

        self.save_new_topic(self.TOPIC_ID_3,
                            self.owner_id,
                            name=self.TOPIC_NAME_3,
                            url_fragment='topic-three',
                            description='A new topic',
                            canonical_story_ids=[],
                            additional_story_ids=[],
                            uncategorized_skill_ids=[],
                            subtopics=[self.subtopic_1],
                            next_subtopic_id=1)
        self.save_new_story(self.STORY_ID_3, self.owner_id, self.TOPIC_ID_3)
        topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_3,
                                           self.STORY_ID_3)

        topic_services.publish_story(self.TOPIC_ID_3, self.STORY_ID_3,
                                     self.admin_id)
        topic_services.publish_topic(self.TOPIC_ID_3, self.admin_id)

        state_name = 'state_name'
        version = 1

        learner_progress_services.mark_exploration_as_completed(
            self.viewer_id, self.EXP_ID_1)
        learner_progress_services.mark_exploration_as_incomplete(
            self.viewer_id, self.EXP_ID_2, state_name, version)
        learner_progress_services.add_exp_to_learner_playlist(
            self.viewer_id, self.EXP_ID_3)

        learner_progress_services.mark_collection_as_completed(
            self.viewer_id, self.COL_ID_1)
        learner_progress_services.mark_collection_as_incomplete(
            self.viewer_id, self.COL_ID_2)
        learner_progress_services.add_collection_to_learner_playlist(
            self.viewer_id, self.COL_ID_3)

        learner_progress_services.mark_story_as_completed(
            self.viewer_id, self.STORY_ID_1)

        learner_progress_services.mark_topic_as_learnt(self.viewer_id,
                                                       self.TOPIC_ID_1)
        learner_progress_services.record_topic_started(self.viewer_id,
                                                       self.TOPIC_ID_2)
        learner_progress_services.validate_and_add_topic_to_learn_goal(
            self.viewer_id, self.TOPIC_ID_3)

        response = self.get_json(feconf.LEARNER_DASHBOARD_IDS_DATA_URL)
        learner_dashboard_activity_ids = (
            response['learner_dashboard_activity_ids'])

        self.assertEqual(
            learner_dashboard_activity_ids['completed_exploration_ids'],
            [self.EXP_ID_1])
        self.assertEqual(
            learner_dashboard_activity_ids['incomplete_exploration_ids'],
            [self.EXP_ID_2])
        self.assertEqual(
            learner_dashboard_activity_ids['exploration_playlist_ids'],
            [self.EXP_ID_3])

        self.assertEqual(
            learner_dashboard_activity_ids['completed_collection_ids'],
            [self.COL_ID_1])
        self.assertEqual(
            learner_dashboard_activity_ids['incomplete_collection_ids'],
            [self.COL_ID_2])
        self.assertEqual(
            learner_dashboard_activity_ids['collection_playlist_ids'],
            [self.COL_ID_3])

        self.assertEqual(learner_dashboard_activity_ids['completed_story_ids'],
                         [self.STORY_ID_1])

        self.assertEqual(learner_dashboard_activity_ids['learnt_topic_ids'],
                         [self.TOPIC_ID_1])
        self.assertEqual(
            learner_dashboard_activity_ids['partially_learnt_topic_ids'],
            [self.TOPIC_ID_2])
        self.assertEqual(learner_dashboard_activity_ids['topic_ids_to_learn'],
                         [self.TOPIC_ID_3])