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_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_get_all_topic_ids_in_learn(self) -> None: self.assertEqual( learner_goals_services.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( learner_goals_services.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( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2])
def test_add_topic_to_learner_goal(self): self.login(self.VIEWER_EMAIL) csrf_token = self.get_new_csrf_token() # 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) self.assertEqual( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1]) # Add another topic. self.post_json('%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, self.TOPIC_ID_2), {}, csrf_token=csrf_token) self.assertEqual( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2]) # If a topic belongs to the completed list, it should not be added. learner_progress_services.mark_topic_as_learnt(self.viewer_id, self.TOPIC_ID_3) response = self.post_json( '%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, self.TOPIC_ID_3), {}, csrf_token=csrf_token) self.assertEqual(response['belongs_to_learnt_list'], True) self.assertEqual( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2]) # Fail to add one topic to the learner goal. response = self.post_json( '%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, 'InvalidActivityType', self.TOPIC_ID_1), {}, csrf_token=csrf_token, expected_status_int=400) self.assertEqual(response['error'], 'Invalid activityType: InvalidActivityType') # Now we begin testing of not exceeding the limit of activities in the # learner goals. # Add feconf.MAX_CURRENT_GOALS_COUNT - 2 activities to reach # the maximum limit. for topic_id in python_utils.RANGE(2, feconf.MAX_CURRENT_GOALS_COUNT + 1): self.post_json('%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, 'topic_id_%s' % topic_id), {}, csrf_token=csrf_token) # Now if we try and add a topic we should get a message saying we # are exceeding the limit. response = self.post_json( '%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, 'topic_id_%s' % python_utils.UNICODE(feconf.MAX_CURRENT_GOALS_COUNT + 3)), {}, csrf_token=csrf_token) self.assertEqual(response['goals_limit_exceeded'], True) self.logout()