def test_delete_exp_opportunities_corresponding_to_story_when_story_deleted( self): opportunity_models.ExplorationOpportunitySummaryModel( id='exp_1', topic_id='topic_id', topic_name='topic_name', story_id='story_id', story_title='story_title', chapter_title='chapter_title', content_count=1, ).put() opportunity_models.ExplorationOpportunitySummaryModel( id='exp_2', topic_id='topic_id', topic_name='topic_name', story_id='story_id', story_title='story_title', chapter_title='chapter_title', content_count=1, ).put() opportunity_services.delete_exp_opportunities_corresponding_to_story( 'story_id') self.assertIsNone( opportunity_models.ExplorationOpportunitySummaryModel.get( 'exp_1', strict=False)) self.assertIsNone( opportunity_models.ExplorationOpportunitySummaryModel.get( 'exp_2', strict=False))
def delete_story(committer_id, story_id, force_deletion=False): """Deletes the story with the given story_id. Args: committer_id: str. ID of the committer. story_id: str. ID of the story to be deleted. force_deletion: bool. If true, the story and its history are fully deleted and are unrecoverable. Otherwise, the story and all its history are marked as deleted, but the corresponding models are still retained in the datastore. This last option is the preferred one. """ story_model = story_models.StoryModel.get(story_id, strict=False) if story_model is not None: story = story_fetchers.get_story_from_model(story_model) exp_ids = story.story_contents.get_all_linked_exp_ids() story_model.delete( committer_id, feconf.COMMIT_MESSAGE_STORY_DELETED, force_deletion=force_deletion ) # Reject the suggestions related to the exploration used in # the story. suggestion_services.auto_reject_translation_suggestions_for_exp_ids( exp_ids) exploration_context_models = ( exp_models.ExplorationContextModel.get_all().filter( exp_models.ExplorationContextModel.story_id == story_id ).fetch() ) exp_models.ExplorationContextModel.delete_multi( exploration_context_models ) # This must come after the story is retrieved. Otherwise the memcache # key will be reinstated. caching_services.delete_multi( caching_services.CACHE_NAMESPACE_STORY, None, [story_id]) # Delete the summary of the story (regardless of whether # force_deletion is True or not). delete_story_summary(story_id) # Delete the opportunities available. opportunity_services.delete_exp_opportunities_corresponding_to_story( story_id)