Пример #1
0
    def test_remove_exploration_from_learner_playlist(self):
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [])

        # Add explorations to learner playlist.
        learner_playlist_services.mark_exploration_to_be_played_later(
            self.user_id, self.EXP_ID_0)
        learner_playlist_services.mark_exploration_to_be_played_later(
            self.user_id, self.EXP_ID_1)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [self.EXP_ID_0, self.EXP_ID_1])

        # Removing an exploration.
        learner_playlist_services.remove_exploration_from_learner_playlist(
            self.user_id, self.EXP_ID_0)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [self.EXP_ID_1])

        # Removing the same exploration again has no effect.
        learner_playlist_services.remove_exploration_from_learner_playlist(
            self.user_id, self.EXP_ID_0)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [self.EXP_ID_1])

        # Removing the second exploration.
        learner_playlist_services.remove_exploration_from_learner_playlist(
            self.user_id, self.EXP_ID_1)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [])
    def test_nunmber_of_explorations_cannot_exceed_max(self):
        # Add MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT explorations.
        exp_ids = [
            'SAMPLE_EXP_ID_%s' % index
            for index in range(0, MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT)
        ]
        for exp_id in exp_ids:
            learner_progress_services.add_exp_to_learner_playlist(
                self.user_id, exp_id)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         exp_ids)

        # Now if we try to add another exploration at the end of the list,
        # it shouldn't be added as the list length would exceed
        # MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT.
        learner_playlist_services.mark_exploration_to_be_played_later(
            self.user_id,
            'SAMPLE_EXP_ID_MAX',
            position_to_be_inserted=MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         exp_ids)

        # Also if we try adding another exploration at no specific location,
        # it shouldn't be added as the list length would exceed
        # MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT.
        learner_playlist_services.mark_exploration_to_be_played_later(
            self.user_id, 'SAMPLE_EXP_ID_MAX')
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         exp_ids)
    def test_mark_exploration_as_completed(self):
        self.assertEqual(self._get_all_completed_exp_ids(self.user_id), [])

        # Add an exploration to the completed list of a learner.
        learner_progress_services.mark_exploration_as_completed(
            self.user_id, self.EXP_ID_0)
        self.assertEqual(self._get_all_completed_exp_ids(self.user_id),
                         [self.EXP_ID_0])

        # Completing an exploration again has no effect.
        learner_progress_services.mark_exploration_as_completed(
            self.user_id, self.EXP_ID_0)
        self.assertEqual(self._get_all_completed_exp_ids(self.user_id),
                         [self.EXP_ID_0])

        state_name = 'state_name'
        version = 1

        # Add an exploration to the in progress list of the learner.
        learner_progress_services.mark_exploration_as_incomplete(
            self.user_id, self.EXP_ID_1, state_name, version)
        self.assertEqual(self._get_all_incomplete_exp_ids(self.user_id),
                         [self.EXP_ID_1])
        # Add an exploration to the learner playlist of the learner.
        learner_playlist_services.mark_exploration_to_be_played_later(
            self.user_id, self.EXP_ID_3)
        self.assertEqual(
            learner_playlist_services.get_all_exp_ids_in_learner_playlist(
                self.user_id), [self.EXP_ID_3])

        # Test that on adding an incomplete exploration to the completed list
        # it gets removed from the incomplete list.
        learner_progress_services.mark_exploration_as_completed(
            self.user_id, self.EXP_ID_1)
        self.assertEqual(self._get_all_completed_exp_ids(self.user_id),
                         [self.EXP_ID_0, self.EXP_ID_1])
        self.assertEqual(self._get_all_incomplete_exp_ids(self.user_id), [])

        # Test that on adding an exploration to the completed list, it gets
        # removed from the learner playlist.
        learner_progress_services.mark_exploration_as_completed(
            self.user_id, self.EXP_ID_3)
        self.assertEqual(self._get_all_completed_exp_ids(self.user_id),
                         [self.EXP_ID_0, self.EXP_ID_1, self.EXP_ID_3])
        self.assertEqual(
            learner_playlist_services.get_all_exp_ids_in_learner_playlist(
                self.user_id), [])

        # Test that an exploration created by the user is not added to the
        # completed list.
        learner_progress_services.mark_exploration_as_completed(
            self.user_id, self.EXP_ID_2)
        self.assertEqual(self._get_all_completed_exp_ids(self.user_id),
                         [self.EXP_ID_0, self.EXP_ID_1, self.EXP_ID_3])
Пример #4
0
    def test_get_all_exp_ids_in_learner_playlist(self):
        self.assertEqual(
            learner_playlist_services.get_all_exp_ids_in_learner_playlist(
                self.user_id), [])

        # Add an exploration to the learner playlist.
        learner_playlist_services.mark_exploration_to_be_played_later(
            self.user_id, self.EXP_ID_0)
        self.assertEqual(
            learner_playlist_services.get_all_exp_ids_in_learner_playlist(
                self.user_id), [self.EXP_ID_0])

        # Add another exploration.
        learner_playlist_services.mark_exploration_to_be_played_later(
            self.user_id, self.EXP_ID_1)
        self.assertEqual(
            learner_playlist_services.get_all_exp_ids_in_learner_playlist(
                self.user_id), [self.EXP_ID_0, self.EXP_ID_1])
Пример #5
0
def add_exp_to_learner_playlist(user_id,
                                exploration_id,
                                position_to_be_inserted=None):
    """This function checks if the exploration exists in the completed list or
    the incomplete list. If it does not exist we call the function in learner
    playlist services to add the exploration to the play later list.

    Args:
        user_id: str. The id of the user.
        exploration_id: str. The id of the exploration to be added to the
            learner playlist.
        position_to_be_inserted: int|None. If this is specified the exploration
            gets inserted at the given position. Otherwise it gets added at the
            end.

    Returns:
        (bool, bool, bool). The first boolean indicates whether the exploration
            already exists in either of the "completed explorations" or
            "incomplete explorations" lists, the second boolean indicates
            whether the playlist limit of the user has been
            exceeded, and the third boolean indicates whether the exploration
            belongs to the created or edited explorations of the user.
    """
    completed_exploration_ids = get_all_completed_exp_ids(user_id)
    incomplete_exploration_ids = get_all_incomplete_exp_ids(user_id)
    playlist_limit_exceeded = False
    belongs_to_subscribed_activities = False
    belongs_to_completed_or_incomplete_list = False

    if (exploration_id not in completed_exploration_ids
            and exploration_id not in incomplete_exploration_ids):

        (playlist_limit_exceeded, belongs_to_subscribed_activities) = (
            learner_playlist_services.mark_exploration_to_be_played_later(
                user_id,
                exploration_id,
                position_to_be_inserted=position_to_be_inserted))

        belongs_to_completed_or_incomplete_list = False

    else:
        belongs_to_completed_or_incomplete_list = True

    return (belongs_to_completed_or_incomplete_list, playlist_limit_exceeded,
            belongs_to_subscribed_activities)
Пример #6
0
    def test_mark_exploration_to_be_played_later(self):
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [])

        # Add an exploration to the learner playlist.
        learner_progress_services.add_exp_to_learner_playlist(
            self.user_id, self.EXP_ID_0)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [self.EXP_ID_0])

        # Add another exploration.
        learner_progress_services.add_exp_to_learner_playlist(
            self.user_id, self.EXP_ID_1)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [self.EXP_ID_0, self.EXP_ID_1])

        # Add the first exploration in a different position.
        learner_progress_services.add_exp_to_learner_playlist(
            self.user_id, self.EXP_ID_0, 1)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [self.EXP_ID_1, self.EXP_ID_0])

        # Add the first exploration in the first position.
        learner_progress_services.add_exp_to_learner_playlist(
            self.user_id, self.EXP_ID_0, 0)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [self.EXP_ID_0, self.EXP_ID_1])

        # Add an exploration to the in progress list of the user.
        state_name = 'state_name'
        version = 1
        learner_progress_services.mark_exploration_as_incomplete(
            self.user_id, self.EXP_ID_3, state_name, version)

        # Test that the exploration added to the in progress list doesn't get
        # added to the learner playlist.
        learner_progress_services.add_exp_to_learner_playlist(
            self.user_id, self.EXP_ID_3)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [self.EXP_ID_0, self.EXP_ID_1])

        # Empty the learner playlist.
        learner_playlist_services.remove_exploration_from_learner_playlist(
            self.user_id, self.EXP_ID_0)
        learner_playlist_services.remove_exploration_from_learner_playlist(
            self.user_id, self.EXP_ID_1)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         [])

        # Test that the length of the learner playlist doesn't exceed
        # MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT.
        # List of explorations to be added.
        exp_ids = [
            'SAMPLE_EXP_ID_%s' % index
            for index in range(0, MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT)
        ]
        for exp_id in exp_ids:
            learner_progress_services.add_exp_to_learner_playlist(
                self.user_id, exp_id)
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         exp_ids)

        # Now if we try adding another exploration, it shouldn't be added as the
        # list length would exceed MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT.
        learner_playlist_services.mark_exploration_to_be_played_later(
            self.user_id, 'SAMPLE_EXP_ID')

        # The list still remains the same.
        self.assertEqual(self._get_all_learner_playlist_exp_ids(self.user_id),
                         exp_ids)
    def test_mark_exploration_as_incomplete(self):
        self.assertEqual(self._get_all_incomplete_exp_ids(self.user_id), [])

        state_name = u'state name'
        version = 1

        exp_details = {
            'timestamp': datetime.datetime.utcnow(),
            'state_name': state_name,
            'version': version
        }

        # Add an exploration to the incomplete list of a learner.
        learner_progress_services.mark_exploration_as_incomplete(
            self.user_id, self.EXP_ID_0, state_name, version)
        self.assertEqual(self._get_all_incomplete_exp_ids(self.user_id),
                         [self.EXP_ID_0])
        self._check_if_exp_details_match(
            self._get_incomplete_exp_details(self.user_id, self.EXP_ID_0),
            exp_details)

        state_name = u'new_state_name'
        version = 2

        modified_exp_details = {
            'timestamp': datetime.datetime.utcnow(),
            'state_name': state_name,
            'version': version
        }

        # On adding an exploration again, its details are updated to the latest
        # version.
        learner_progress_services.mark_exploration_as_incomplete(
            self.user_id, self.EXP_ID_0, state_name, version)
        self.assertEqual(self._get_all_incomplete_exp_ids(self.user_id),
                         [self.EXP_ID_0])
        self._check_if_exp_details_match(
            self._get_incomplete_exp_details(self.user_id, self.EXP_ID_0),
            modified_exp_details)

        # If an exploration has already been completed, it is not added.
        learner_progress_services.mark_exploration_as_completed(
            self.user_id, self.EXP_ID_1)
        learner_progress_services.mark_exploration_as_incomplete(
            self.user_id, self.EXP_ID_1, state_name, version)
        self.assertEqual(self._get_all_incomplete_exp_ids(self.user_id),
                         [self.EXP_ID_0])

        # Add an exploration to the learner playlist.
        learner_playlist_services.mark_exploration_to_be_played_later(
            self.user_id, self.EXP_ID_3)
        self.assertEqual(
            learner_playlist_services.get_all_exp_ids_in_learner_playlist(
                self.user_id), [self.EXP_ID_3])

        # Test that on adding an exploration to the incomplete list, it gets
        # removed from the learner playlist.
        learner_progress_services.mark_exploration_as_incomplete(
            self.user_id, self.EXP_ID_3, state_name, version)
        self.assertEqual(self._get_all_incomplete_exp_ids(self.user_id),
                         [self.EXP_ID_0, self.EXP_ID_3])
        self.assertEqual(
            learner_playlist_services.get_all_exp_ids_in_learner_playlist(
                self.user_id), [])

        # Test that an exploration created by the user is not added to the
        # incomplete list.
        learner_progress_services.mark_exploration_as_incomplete(
            self.user_id, self.EXP_ID_2, state_name, version)
        self.assertEqual(self._get_all_incomplete_exp_ids(self.user_id),
                         [self.EXP_ID_0, self.EXP_ID_3])