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_mark_topic_as_learnt_and_story_as_completed(self): self.NEW_USER_EMAIL = '*****@*****.**' self.NEW_USER_USERNAME = '******' self.save_new_valid_exploration(self.EXP_ID_3, self.admin_id, title='Title 3', end_state_name='End', correctness_feedback_enabled=True) self.publish_exploration(self.admin_id, self.EXP_ID_3) story = story_domain.Story.create_default_story( self.NEW_STORY_ID, 'Title', 'Description', self.TOPIC_ID, self.STORY_URL_FRAGMENT_TWO) story.meta_tag_content = 'story meta content' exp_summary_dicts = ( summary_services.get_displayable_exp_summary_dicts_matching_ids( [self.EXP_ID_3], user=self.admin)) self.node_1 = { 'id': self.NODE_ID_1, 'title': 'Title 1', 'description': 'Description 1', 'thumbnail_filename': 'image_1.svg', 'thumbnail_bg_color': constants.ALLOWED_THUMBNAIL_BG_COLORS['chapter'][0], 'thumbnail_size_in_bytes': 21131, 'destination_node_ids': [], 'acquired_skill_ids': [], 'prerequisite_skill_ids': [], 'outline': '', 'outline_is_finalized': False, 'exploration_id': self.EXP_ID_3, 'exp_summary_dict': exp_summary_dicts[0], 'completed': False } story.story_contents.nodes = [ story_domain.StoryNode.from_dict(self.node_1) ] self.nodes = story.story_contents.nodes story.story_contents.initial_node_id = 'node_1' story.story_contents.next_node_id = 'node_2' story_services.save_new_story(self.admin_id, story) topic_services.add_canonical_story(self.admin_id, self.TOPIC_ID, self.NEW_STORY_ID) topic_services.publish_story(self.TOPIC_ID, self.NEW_STORY_ID, self.admin_id) csrf_token = self.get_new_csrf_token() 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_progress_services.get_all_completed_story_ids( self.viewer_id)), 1) def _mock_none_function(_): """Mocks None.""" return None story_fetchers_swap = self.swap(story_fetchers, 'get_story_by_id', _mock_none_function) with story_fetchers_swap: with self.capture_logging( min_level=logging.ERROR) as captured_logs: 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(captured_logs, [ 'Could not find a story corresponding to %s ' 'id.' % self.STORY_ID ])