コード例 #1
0
    def test_remove_topic_from_learner_goals(self):
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [])

        # Add topic to learner goals.
        learner_goals_services.mark_topic_to_learn(self.viewer_id,
                                                   self.TOPIC_ID_1)
        learner_goals_services.mark_topic_to_learn(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])

        # Removing a topic.
        learner_goals_services.remove_topics_from_learn_goal(
            self.viewer_id, [self.TOPIC_ID_1])
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                         [self.TOPIC_ID_2])

        # Removing the same topic raises error.
        with self.assertRaisesRegexp(
                Exception,
                'The topic id Topic_id_1 is not present in LearnerGoalsModel'):
            learner_goals_services.remove_topics_from_learn_goal(
                self.viewer_id, [self.TOPIC_ID_1])

        # Removing the second topic.
        learner_goals_services.remove_topics_from_learn_goal(
            self.viewer_id, [self.TOPIC_ID_2])
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [])
コード例 #2
0
    def test_get_all_topic_ids_in_learn(self):
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [])

        # Add an topic to the learner goals.
        learner_goals_services.mark_topic_to_learn(self.viewer_id,
                                                   self.TOPIC_ID_1)
        self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id),
                         [self.TOPIC_ID_1])

        # Add another topic.
        learner_goals_services.mark_topic_to_learn(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])
コード例 #3
0
    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)