Exemplo n.º 1
0
    def delete(self, topic_id):
        """Handles Delete requests."""
        if not constants.ENABLE_NEW_STRUCTURE_EDITORS:
            raise self.PageNotFoundException

        topic_domain.Topic.require_valid_topic_id(topic_id)
        topic = topic_services.get_topic_by_id(topic_id, strict=False)
        if topic is None:
            raise self.PageNotFoundException(
                'The topic with the given id doesn\'t exist.')
        topic_services.delete_topic(self.user_id, topic_id)

        self.render_json(self.values)
Exemplo n.º 2
0
    def test_opportunity_get_deleted_with_deleting_topic(self):
        self.add_exploration_0_to_story()

        translation_opportunities, _, _ = (
            opportunity_services.get_translation_opportunities(
                'hi', 'topic', None))
        self.assertEqual(len(translation_opportunities), 1)

        topic_services.delete_topic(self.owner_id, self.TOPIC_ID)

        translation_opportunities, _, _ = (
            opportunity_services.get_translation_opportunities(
                'hi', 'topic', None))
        self.assertEqual(len(translation_opportunities), 0)
Exemplo n.º 3
0
    def test_regeneration_job_for_deleted_topic_returns_empty_list_output(self):
        exp_opp_summary_model_regen_job_class = (
            opportunity_jobs_one_off
            .ExplorationOpportunitySummaryModelRegenerationJob)

        topic_services.delete_topic(self.owner_id, self.topic_id_1)
        topic_services.delete_topic(self.owner_id, self.topic_id_2)

        job_id = exp_opp_summary_model_regen_job_class.create_new()
        exp_opp_summary_model_regen_job_class.enqueue(job_id)

        self.assertEqual(
            self.count_jobs_in_taskqueue(
                taskqueue_services.QUEUE_NAME_ONE_OFF_JOBS), 1)
        self.process_and_flush_pending_tasks()

        output = exp_opp_summary_model_regen_job_class.get_output(job_id)
        self.assertEqual(output, [])
Exemplo n.º 4
0
    def test_job_with_topic_deleted_skips(self):
        """Tests that PopulateThumbnailSizeOneOffJob skips deleted topics."""
        self.save_new_topic(self.TOPIC_ID, self.albert_id)
        topic_services.delete_topic(self.albert_id, self.TOPIC_ID)

        # Start migration job on sample topic.
        job_id = (
            topic_jobs_one_off.PopulateTopicThumbnailSizeOneOffJob.create_new()
        )
        topic_jobs_one_off.PopulateTopicThumbnailSizeOneOffJob.enqueue(job_id)

        # This running without errors indicates that deleted topics are
        # skipped.
        self.process_and_flush_pending_mapreduce_tasks()

        output = (
            topic_jobs_one_off.PopulateTopicThumbnailSizeOneOffJob.get_output(
                job_id))
        expected = [[u'topic_deleted', 1]]

        self.assertEqual(expected, [ast.literal_eval(x) for x in output])
    def test_opportunity_get_deleted_with_deleting_topic(self):
        story_services.update_story(
            self.owner_id, self.STORY_ID, [story_domain.StoryChange({
                'cmd': 'add_story_node',
                'node_id': 'node_1',
                'title': 'Node1',
            }), story_domain.StoryChange({
                'cmd': 'update_story_node_property',
                'property_name': 'exploration_id',
                'node_id': 'node_1',
                'old_value': None,
                'new_value': '0'
            })], 'Changes.')

        translation_opportunities, _, _ = (
            opportunity_services.get_translation_opportunities('hi', None))
        self.assertEqual(len(translation_opportunities), 1)

        topic_services.delete_topic(self.owner_id, self.TOPIC_ID)

        translation_opportunities, _, _ = (
            opportunity_services.get_translation_opportunities('hi', None))
        self.assertEqual(len(translation_opportunities), 0)
Exemplo n.º 6
0
    def test_job_skips_deleted_topic(self):
        """Tests that RemoveDeletedSkillsFromTopicOneOffJob job skips
        deleted topic and does not attempt to remove uncategorized skills for
        skills that are deleted.
        """
        topic = topic_domain.Topic.create_default_topic(
            self.TOPIC_ID, 'A name', 'abbrev', 'description')
        topic.add_uncategorized_skill_id('skill_1')
        topic.add_uncategorized_skill_id('skill_2')
        topic_services.save_new_topic(self.albert_id, topic)

        # Delete the topic before migration occurs.
        topic_services.delete_topic(self.albert_id, self.TOPIC_ID)

        # Ensure the topic is deleted.
        with self.assertRaisesRegexp(Exception, 'Entity .* not found'):
            topic_fetchers.get_topic_by_id(self.TOPIC_ID)

        # Start migration job on sample topic.
        job_id = (topic_jobs_one_off.RemoveDeletedSkillsFromTopicOneOffJob.
                  create_new())
        topic_jobs_one_off.RemoveDeletedSkillsFromTopicOneOffJob.enqueue(
            job_id)

        # This running without errors indicates the deleted topic is
        # being ignored.
        self.process_and_flush_pending_mapreduce_tasks()

        # Ensure the topic is still deleted.
        with self.assertRaisesRegexp(Exception, 'Entity .* not found'):
            topic_fetchers.get_topic_by_id(self.TOPIC_ID)

        output = (topic_jobs_one_off.RemoveDeletedSkillsFromTopicOneOffJob.
                  get_output(job_id))
        expected = [[u'topic_deleted', [u'Encountered 1 deleted topics.']]]
        self.assertEqual(expected, [ast.literal_eval(x) for x in output])