def test_remove_collection_from_learner_playlist(self): self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), []) # Add collections to learner playlist. learner_playlist_services.mark_collection_to_be_played_later( self.user_id, self.COL_ID_0) learner_playlist_services.mark_collection_to_be_played_later( self.user_id, self.COL_ID_1) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), [self.COL_ID_0, self.COL_ID_1]) # Removing a collection. learner_playlist_services.remove_collection_from_learner_playlist( self.user_id, self.COL_ID_0) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), [self.COL_ID_1]) # Removing the same collection again has no effect. learner_playlist_services.remove_collection_from_learner_playlist( self.user_id, self.COL_ID_0) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), [self.COL_ID_1]) # Removing the second collection. learner_playlist_services.remove_collection_from_learner_playlist( self.user_id, self.COL_ID_1) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), [])
def test_number_of_collections_cannot_exceed_max(self): # Add MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT collections. col_ids = [ 'SAMPLE_COL_ID_%s' % index for index in range(0, MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT) ] for col_id in col_ids: learner_progress_services.add_collection_to_learner_playlist( self.user_id, col_id) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), col_ids) # Now if we try to add another collection 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_collection_to_be_played_later( self.user_id, 'SAMPLE_COL_ID_MAX', position_to_be_inserted=MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), col_ids) # Now if we try adding another collection at no specific position, # it shouldn't be added as the list length would exceed # MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT. learner_playlist_services.mark_collection_to_be_played_later( self.user_id, 'SAMPLE_COL_ID_MAX') self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), col_ids)
def test_mark_collection_as_completed(self): self.assertEqual(self._get_all_completed_collection_ids(self.user_id), []) # Add a collection to the completed list. learner_progress_services.mark_collection_as_completed( self.user_id, self.COL_ID_0) self.assertEqual(self._get_all_completed_collection_ids(self.user_id), [self.COL_ID_0]) # Completing a collection again has no effect. learner_progress_services.mark_collection_as_completed( self.user_id, self.COL_ID_0) self.assertEqual(self._get_all_completed_collection_ids(self.user_id), [self.COL_ID_0]) # Add a collection to the incomplete list. learner_progress_services.mark_collection_as_incomplete( self.user_id, self.COL_ID_1) self.assertEqual(self._get_all_incomplete_collection_ids(self.user_id), [self.COL_ID_1]) # If the collection is present in the incomplete list, on completion # it is removed from the incomplete list and added to the complete # list. learner_progress_services.mark_collection_as_completed( self.user_id, self.COL_ID_1) self.assertEqual(self._get_all_incomplete_collection_ids(self.user_id), []) self.assertEqual(self._get_all_completed_collection_ids(self.user_id), [self.COL_ID_0, self.COL_ID_1]) # Add a collection to the learner playlist of the learner. learner_playlist_services.mark_collection_to_be_played_later( self.user_id, self.COL_ID_3) self.assertEqual( learner_playlist_services. get_all_collection_ids_in_learner_playlist( # pylint: disable=line-too-long self.user_id), [self.COL_ID_3]) # Test that on adding a collection to the completed list, it gets # removed from the learner playlist. learner_progress_services.mark_collection_as_completed( self.user_id, self.COL_ID_3) self.assertEqual(self._get_all_completed_collection_ids(self.user_id), [self.COL_ID_0, self.COL_ID_1, self.COL_ID_3]) self.assertEqual( learner_playlist_services. get_all_collection_ids_in_learner_playlist( # pylint: disable=line-too-long self.user_id), []) # Test that a collection created by the user is not added to the # completed list. learner_progress_services.mark_collection_as_completed( self.user_id, self.COL_ID_2) self.assertEqual(self._get_all_completed_collection_ids(self.user_id), [self.COL_ID_0, self.COL_ID_1, self.COL_ID_3])
def test_get_all_learner_playlist_collection_ids(self): self.assertEqual( learner_playlist_services.get_all_collection_ids_in_learner_playlist( # pylint: disable=line-too-long self.user_id), []) # Add a collection to the learner playlist. learner_playlist_services.mark_collection_to_be_played_later( self.user_id, self.COL_ID_0) self.assertEqual( learner_playlist_services.get_all_collection_ids_in_learner_playlist( # pylint: disable=line-too-long self.user_id), [self.COL_ID_0]) # Add another collection. learner_playlist_services.mark_collection_to_be_played_later( self.user_id, self.COL_ID_1) self.assertEqual( learner_playlist_services.get_all_collection_ids_in_learner_playlist( # pylint: disable=line-too-long self.user_id), [self.COL_ID_0, self.COL_ID_1])
def add_collection_to_learner_playlist(user_id, collection_id, position_to_be_inserted=None): """This function checks if the collection 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 collection to the play later list. Args: user_id: str. The id of the user. collection_id: str. The id of the collection to be added to the learner playlist. position_to_be_inserted: int|None. If this is specified the collection gets inserted at the given position. Otherwise it gets added at the end. Returns: (bool, bool, bool). The first boolean indicates whether the collection already exists in either of the "completed collections" or "incomplete collections" lists, the second boolean indicates whether the playlist limit of the user has been exceeded, and the third boolean indicates whether the collection belongs to the created or edited collections of the user. """ completed_collection_ids = get_all_completed_collection_ids(user_id) incomplete_collection_ids = get_all_incomplete_collection_ids(user_id) playlist_limit_exceeded = False belongs_to_subscribed_activities = False belongs_to_completed_or_incomplete_list = False if (collection_id not in completed_collection_ids and collection_id not in incomplete_collection_ids): (playlist_limit_exceeded, belongs_to_subscribed_activities) = ( learner_playlist_services.mark_collection_to_be_played_later( user_id, collection_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)
def test_mark_collection_to_be_played_later(self): self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), []) # Add a collection to the learner playlist. learner_progress_services.add_collection_to_learner_playlist( self.user_id, self.COL_ID_0) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), [self.COL_ID_0]) # Add another collection. learner_progress_services.add_collection_to_learner_playlist( self.user_id, self.COL_ID_1) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), [self.COL_ID_0, self.COL_ID_1]) # Add the first collection in a different position. learner_progress_services.add_collection_to_learner_playlist( self.user_id, self.COL_ID_0, 1) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), [self.COL_ID_1, self.COL_ID_0]) # Add the first collection in the first position. learner_progress_services.add_collection_to_learner_playlist( self.user_id, self.COL_ID_0, 0) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), [self.COL_ID_0, self.COL_ID_1]) # Add a collection to the in progress list of the user. learner_progress_services.mark_collection_as_incomplete( self.user_id, self.COL_ID_3) # Test that the collection added to the in progress list doesn't get # added to the learner playlist. learner_progress_services.add_collection_to_learner_playlist( self.user_id, self.COL_ID_3) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), [self.COL_ID_0, self.COL_ID_1]) # Empty the learner playlist. learner_playlist_services.remove_collection_from_learner_playlist( self.user_id, self.COL_ID_0) learner_playlist_services.remove_collection_from_learner_playlist( self.user_id, self.COL_ID_1) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), []) # Test that the length of the learner playlist doesn't exceed # MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT. # List of collections to be added. collection_ids = ([ 'SAMPLE_COLLECTION_ID_%s' % index for index in range(0, MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT) ]) for collection_id in collection_ids: learner_progress_services.add_collection_to_learner_playlist( self.user_id, collection_id) self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), collection_ids) # Now if we try adding another collection, it shouldn't be added as the # list length would exceed MAX_LEARNER_PLAYLIST_ACTIVITY_COUNT. learner_playlist_services.mark_collection_to_be_played_later( self.user_id, 'SAMPLE_COLLECTION_ID') # The list still remains the same. self.assertEqual( self._get_all_learner_playlist_collection_ids(self.user_id), collection_ids)