Example #1
0
    def test_migration_job_skips_deleted_topic(self):
        """Tests that the topic migration job skips deleted topic
        and does not attempt to migrate.
        """
        topic = topic_domain.Topic.create_default_topic(self.TOPIC_ID,
                                                        name='A name')
        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_services.get_topic_by_id(self.TOPIC_ID)

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

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

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

        output = topic_jobs_one_off.TopicMigrationOneOffJob.get_output(job_id)  # pylint: disable=line-too-long
        expected = [[u'topic_deleted', [u'Encountered 1 deleted topics.']]]
        self.assertEqual(expected, [ast.literal_eval(x) for x in output])
Example #2
0
    def test_migration_job_converts_old_topic(self):
        """Tests that the schema conversion functions work
        correctly and an old topic is converted to new
        version.
        """
        # Generate topic with old(v1) subtopic data.
        self.save_new_topic_with_subtopic_schema_v1(self.TOPIC_ID,
                                                    self.albert_id, 'A name',
                                                    'a name', '', [], [], [],
                                                    2)
        topic = (topic_services.get_topic_by_id(self.TOPIC_ID))
        self.assertEqual(topic.subtopic_schema_version, 1)

        # Start migration job.
        job_id = (topic_jobs_one_off.TopicMigrationOneOffJob.create_new())
        topic_jobs_one_off.TopicMigrationOneOffJob.enqueue(job_id)
        self.process_and_flush_pending_tasks()

        # Verify the topic migrates correctly.
        updated_topic = (topic_services.get_topic_by_id(self.TOPIC_ID))
        self.assertEqual(updated_topic.subtopic_schema_version,
                         feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION)

        output = topic_jobs_one_off.TopicMigrationOneOffJob.get_output(job_id)  # pylint: disable=line-too-long
        expected = [[u'topic_migrated', [u'1 topics successfully migrated.']]]
        self.assertEqual(expected, [ast.literal_eval(x) for x in output])
Example #3
0
    def put(self, topic_id):
        """Updates properties of the given topic."""
        if not feconf.ENABLE_NEW_STRUCTURES:
            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(
                Exception('The topic with the given id doesn\'t exist.'))

        version = self.payload.get('version')
        self._require_valid_version(version, topic.version)

        commit_message = self.payload.get('commit_message')
        change_dicts = self.payload.get('change_dicts')
        change_list = [
            topic_domain.TopicChange(change_dict)
            for change_dict in change_dicts
        ]
        try:
            topic_services.update_topic(
                self.user_id, topic_id, change_list, commit_message)
        except utils.ValidationError as e:
            raise self.InvalidInputException(e)

        topic_dict = topic_services.get_topic_by_id(topic_id).to_dict()

        self.values.update({
            'topic': topic_dict
        })

        self.render_json(self.values)
Example #4
0
    def put(self, topic_id):
        """Updates properties of the given topic.
        Also, each change_dict given for editing should have an additional
        property called is_topic_change, which would be a boolean. If True, it
        means that change is for a topic (includes adding and removing
        subtopics), while False would mean it is for a Subtopic Page (this
        includes editing its html data as of now).
        """
        if not feconf.ENABLE_NEW_STRUCTURES:
            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(
                Exception('The topic with the given id doesn\'t exist.'))

        version = self.payload.get('version')
        self._require_valid_version(version, topic.version)

        commit_message = self.payload.get('commit_message')
        topic_and_subtopic_page_change_dicts = self.payload.get(
            'topic_and_subtopic_page_change_dicts')
        topic_and_subtopic_page_change_list = []
        for change in topic_and_subtopic_page_change_dicts:
            if change['change_affects_subtopic_page']:
                topic_and_subtopic_page_change_list.append(
                    subtopic_page_domain.SubtopicPageChange(change))
            else:
                topic_and_subtopic_page_change_list.append(
                    topic_domain.TopicChange(change))
        try:
            topic_services.update_topic_and_subtopic_pages(
                self.user_id, topic_id, topic_and_subtopic_page_change_list,
                commit_message)
        except utils.ValidationError as e:
            raise self.InvalidInputException(e)

        topic = topic_services.get_topic_by_id(topic_id, strict=False)
        skill_ids = topic.get_all_skill_ids()

        skill_id_to_description_dict = (
            skill_services.get_skill_descriptions_by_ids(topic_id, skill_ids))

        self.values.update({
            'topic_dict':
            topic.to_dict(),
            'skill_id_to_description_dict':
            skill_id_to_description_dict
        })

        self.render_json(self.values)
Example #5
0
    def test_update_topic_language_code(self):
        topic = topic_services.get_topic_by_id(self.TOPIC_ID)
        self.assertEqual(topic.language_code, 'en')

        changelist = [topic_domain.TopicChange({
            'cmd': topic_domain.CMD_UPDATE_TOPIC_PROPERTY,
            'property_name': topic_domain.TOPIC_PROPERTY_LANGUAGE_CODE,
            'old_value': 'en',
            'new_value': 'bn'
        })]
        topic_services.update_topic_and_subtopic_pages(
            self.user_id, self.TOPIC_ID, changelist, 'Change language code')

        topic = topic_services.get_topic_by_id(self.TOPIC_ID)
        self.assertEqual(topic.language_code, 'bn')
Example #6
0
    def get(self, topic_id):
        """Handles GET requests."""
        if not constants.ENABLE_NEW_STRUCTURE_EDITORS:
            raise self.PageNotFoundException
        topic_domain.Topic.require_valid_topic_id(topic_id)

        start_cursor = self.request.get('cursor')
        topic = topic_services.get_topic_by_id(topic_id)
        skill_ids = topic.get_all_skill_ids()

        question_summaries, skill_descriptions, next_start_cursor = (
            question_services.get_question_summaries_and_skill_descriptions(
                constants.NUM_QUESTIONS_PER_PAGE, skill_ids, start_cursor))
        return_dicts = []
        for index, summary in enumerate(question_summaries):
            return_dicts.append({
                'summary': summary.to_dict(),
                'skill_description': skill_descriptions[index]
            })

        self.values.update({
            'question_summary_dicts': return_dicts,
            'next_start_cursor': next_start_cursor
        })
        self.render_json(self.values)
Example #7
0
    def test_update_topic_additional_story_ids(self):
        topic = topic_services.get_topic_by_id(self.TOPIC_ID)
        self.assertEqual(topic.additional_story_ids, [self.story_id_3])

        changelist = [topic_domain.TopicChange({
            'cmd': topic_domain.CMD_UPDATE_TOPIC_PROPERTY,
            'property_name': topic_domain.TOPIC_PROPERTY_ADDITIONAL_STORY_IDS,
            'old_value': [self.story_id_3],
            'new_value': ['new_story_id']
        })]
        topic_services.update_topic_and_subtopic_pages(
            self.user_id, self.TOPIC_ID, changelist,
            'Change additional story ids')

        topic = topic_services.get_topic_by_id(self.TOPIC_ID)
        self.assertEqual(topic.additional_story_ids, ['new_story_id'])
Example #8
0
    def get(self, topic_id):
        """Handles GET requests."""

        if not feconf.ENABLE_NEW_STRUCTURES:
            raise self.PageNotFoundException
        topic = topic_services.get_topic_by_id(topic_id)
        canonical_story_summaries = story_services.get_story_summaries_by_ids(
            topic.canonical_story_ids)
        additional_story_summaries = story_services.get_story_summaries_by_ids(
            topic.additional_story_ids)

        canonical_story_summary_dicts = [
            summary.to_dict() for summary in canonical_story_summaries
        ]
        additional_story_summary_dicts = [
            summary.to_dict() for summary in additional_story_summaries
        ]

        self.values.update({
            'canonical_story_summary_dicts':
            canonical_story_summary_dicts,
            'additional_story_summary_dicts':
            additional_story_summary_dicts
        })
        self.render_json(self.values)
Example #9
0
    def get(self, topic_id):
        """Handles GET requests."""
        topic = topic_services.get_topic_by_id(topic_id, strict=False)

        if topic is None:
            raise self.PageNotFoundException(
                Exception('The topic with the given id doesn\'t exist.'))

        interaction_ids = feconf.ALLOWED_QUESTION_INTERACTION_IDS

        interaction_dependency_ids = (
            interaction_registry.Registry.get_deduplicated_dependency_ids(
                interaction_ids))
        dependencies_html, additional_angular_modules = (
            dependency_registry.Registry.get_deps_html_and_angular_modules(
                interaction_dependency_ids + self.EDITOR_PAGE_DEPENDENCY_IDS))

        interaction_templates = (interaction_registry.Registry.
                                 get_interaction_html(interaction_ids))

        self.values.update({
            'additional_angular_modules':
            additional_angular_modules,
            'INTERACTION_SPECS':
            interaction_registry.Registry.get_all_specs(),
            'interaction_templates':
            jinja2.utils.Markup(interaction_templates),
            'dependencies_html':
            jinja2.utils.Markup(dependencies_html)
        })

        self.render_template('dist/topic-editor-page.mainpage.html')
    def post(self):
        if not feconf.ENABLE_NEW_STRUCTURES:
            raise self.PageNotFoundException
        topic_id = self.payload.get('topic_id')

        if topic_id is not None:
            topic = topic_services.get_topic_by_id(topic_id, strict=False)
            if topic is None:
                raise self.InvalidInputException

        description = self.payload.get('description')

        skill_domain.Skill.require_valid_description(description)

        new_skill_id = skill_services.get_new_skill_id()
        skill = skill_domain.Skill.create_default_skill(
            new_skill_id, description)
        skill_services.save_new_skill(self.user_id, skill)

        if topic_id is not None:
            topic_services.add_uncategorized_skill(
                self.user_id, topic_id, new_skill_id)

        self.render_json({
            'skillId': new_skill_id
        })
Example #11
0
    def get(self, topic_id, story_id):
        """Populates the data on the individual story page."""
        story_domain.Story.require_valid_story_id(story_id)
        topic_domain.Topic.require_valid_topic_id(topic_id)

        story = story_fetchers.get_story_by_id(story_id, strict=False)
        if story is None:
            raise self.PageNotFoundException

        topic = topic_services.get_topic_by_id(topic_id, strict=False)
        canonical_story_ids = topic.get_canonical_story_ids()
        if story_id not in canonical_story_ids:
            raise self.PageNotFoundException

        for story_reference in topic.canonical_story_references:
            if story_reference.story_id == story_id:
                story_is_published = story_reference.story_is_published

        self.values.update({
            'story': story.to_dict(),
            'topic_name': topic.name,
            'story_is_published': story_is_published
        })

        self.render_json(self.values)
Example #12
0
    def map(item):
        if item.deleted:
            yield (TopicMigrationOneOffJob._DELETED_KEY, 1)
            return

        # Note: the read will bring the topic up to the newest version.
        topic = topic_services.get_topic_by_id(item.id)
        try:
            topic.validate()
        except Exception as e:
            logging.error('Topic %s failed validation: %s' % (item.id, e))
            yield (TopicMigrationOneOffJob._ERROR_KEY,
                   'Topic %s failed validation: %s' % (item.id, e))
            return

        # Write the new topic into the datastore if it's different from
        # the old version.
        if (item.subtopic_schema_version <=
                feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION):
            commit_cmds = [
                topic_domain.TopicChange({
                    'cmd':
                    topic_domain.CMD_MIGRATE_SUBTOPIC_SCHEMA_TO_LATEST_VERSION,  # pylint: disable=line-too-long
                    'from_version':
                    item.subtopic_schema_version,
                    'to_version':
                    feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION
                })
            ]
            topic_services.update_topic_and_subtopic_pages(
                feconf.MIGRATION_BOT_USERNAME, item.id, commit_cmds,
                'Update topic\'s subtopic schema version to %d.' %
                (feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION))
            yield (TopicMigrationOneOffJob._MIGRATED_KEY, 1)
Example #13
0
    def get(self, topic_id, story_id):
        """Handles GET requests."""

        if not constants.ENABLE_NEW_STRUCTURES:
            raise self.PageNotFoundException

        story_domain.Story.require_valid_story_id(story_id)
        topic_domain.Topic.require_valid_topic_id(topic_id)

        story = story_services.get_story_by_id(story_id, strict=False)
        if story is None:
            raise self.PageNotFoundException

        topic = topic_services.get_topic_by_id(topic_id, strict=False)
        if topic is None or story_id not in topic.canonical_story_ids:
            raise self.PageNotFoundException

        self.values.update({
            'story_id': story.id,
            'story_title': story.title,
            'nav_mode': feconf.NAV_MODE_STORY_EDITOR
        })

        self.render_template(
            'pages/story_editor/story_editor.html', redirect_url_on_logout='/')
Example #14
0
    def put(self, topic_id, story_id):
        """Updates properties of the given story."""
        story_domain.Story.require_valid_story_id(story_id)
        topic_domain.Topic.require_valid_topic_id(topic_id)
        story = story_services.get_story_by_id(story_id, strict=False)
        if story is None:
            raise self.PageNotFoundException

        topic = topic_services.get_topic_by_id(topic_id, strict=False)
        if topic is None or story_id not in topic.canonical_story_ids:
            raise self.PageNotFoundException

        version = self.payload.get('version')
        self._require_valid_version(version, story.version)

        commit_message = self.payload.get('commit_message')
        change_dicts = self.payload.get('change_dicts')
        change_list = [
            story_domain.StoryChange(change_dict)
            for change_dict in change_dicts
        ]
        try:
            story_services.update_story(self.user_id, story_id, change_list,
                                        commit_message)
        except utils.ValidationError as e:
            raise self.InvalidInputException(e)

        story_dict = story_services.get_story_by_id(story_id).to_dict()

        self.values.update({'story': story_dict})

        self.render_json(self.values)
Example #15
0
    def get(self, topic_id):
        """Populates the data on the individual topic page."""
        if not feconf.ENABLE_NEW_STRUCTURES:
            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(
                Exception('The topic with the given id doesn\'t exist.'))

        skill_ids = topic.get_all_skill_ids()

        skill_id_to_description_dict = (
            skill_services.get_skill_descriptions_by_ids(topic_id, skill_ids))

        self.values.update({
            'topic_dict':
            topic.to_dict(),
            'skill_id_to_description_dict':
            skill_id_to_description_dict
        })

        self.render_json(self.values)
Example #16
0
    def test_migration_job_does_not_convert_up_to_date_topic(self):
        """Tests that the topic migration job does not convert a
        topic that is already the latest schema version.
        """
        # Create a new topic that should not be affected by the
        # job.
        topic = topic_domain.Topic.create_default_topic(self.TOPIC_ID,
                                                        name='A name')
        topic.add_subtopic(1, title='A subtitle')
        topic_services.save_new_topic(self.albert_id, topic)
        self.assertEqual(topic.subtopic_schema_version,
                         feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION)

        # Start migration job.
        job_id = (topic_jobs_one_off.TopicMigrationOneOffJob.create_new())
        topic_jobs_one_off.TopicMigrationOneOffJob.enqueue(job_id)
        self.process_and_flush_pending_tasks()

        # Verify the topic is exactly the same after migration.
        updated_topic = (topic_services.get_topic_by_id(self.TOPIC_ID))
        self.assertEqual(updated_topic.subtopic_schema_version,
                         feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION)
        self.assertEqual(topic.subtopics[0].to_dict(),
                         updated_topic.subtopics[0].to_dict())

        output = topic_jobs_one_off.TopicMigrationOneOffJob.get_output(job_id)  # pylint: disable=line-too-long
        expected = [[u'topic_migrated', [u'1 topics successfully migrated.']]]
        self.assertEqual(expected, [ast.literal_eval(x) for x in output])
Example #17
0
    def setUp(self):
        super(TopicServicesUnitTests, self).setUp()
        self.TOPIC_ID = topic_services.get_new_topic_id()
        changelist = [topic_domain.TopicChange({
            'cmd': topic_domain.CMD_ADD_SUBTOPIC,
            'title': 'Title',
            'subtopic_id': 1
        })]
        self.save_new_topic(
            self.TOPIC_ID, self.user_id, 'Name', 'Description',
            [self.story_id_1, self.story_id_2], [self.story_id_3],
            [self.skill_id_1, self.skill_id_2], [], 1
        )
        self.signup('*****@*****.**', 'A')
        self.signup('*****@*****.**', 'B')
        self.signup(self.ADMIN_EMAIL, username=self.ADMIN_USERNAME)

        self.user_id_a = self.get_user_id_from_email('*****@*****.**')
        self.user_id_b = self.get_user_id_from_email('*****@*****.**')
        self.user_id_admin = self.get_user_id_from_email(self.ADMIN_EMAIL)
        topic_services.update_topic_and_subtopic_pages(
            self.user_id_admin, self.TOPIC_ID, changelist, 'Added a subtopic')

        self.topic = topic_services.get_topic_by_id(self.TOPIC_ID)
        self.set_admins([self.ADMIN_USERNAME])
        self.set_topic_managers([user_services.get_username(self.user_id_a)])
        self.user_a = user_services.UserActionsInfo(self.user_id_a)
        self.user_b = user_services.UserActionsInfo(self.user_id_b)
        self.user_admin = user_services.UserActionsInfo(self.user_id_admin)
Example #18
0
    def post(self, topic_id):
        """Handles POST requests.
        Currently, this only adds the story to the canonical story id list of
        the topic.
        """
        if not feconf.ENABLE_NEW_STRUCTURES:
            raise self.PageNotFoundException
        topic_domain.Topic.require_valid_topic_id(topic_id)
        title = self.payload.get('title')

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

        story_domain.Story.require_valid_title(title)

        new_story_id = story_services.get_new_story_id()
        story = story_domain.Story.create_default_story(
            new_story_id, title=title)
        story_services.save_new_story(self.user_id, story)
        topic_services.add_canonical_story(self.user_id, topic_id, new_story_id)
        self.render_json({
            'storyId': new_story_id
        })
Example #19
0
    def put(self, topic_id):
        """Updates properties of the given topic.
        Also, each change_dict given for editing should have an additional
        property called is_topic_change, which would be a boolean. If True, it
        means that change is for a topic (includes adding and removing
        subtopics), while False would mean it is for a Subtopic Page (this
        includes editing its html data as of now).
        """
        topic_domain.Topic.require_valid_topic_id(topic_id)
        topic = topic_services.get_topic_by_id(topic_id, strict=False)

        version = self.payload.get('version')
        self._require_valid_version(version, topic.version)

        commit_message = self.payload.get('commit_message')
        topic_and_subtopic_page_change_dicts = self.payload.get(
            'topic_and_subtopic_page_change_dicts')
        topic_and_subtopic_page_change_list = []
        for change in topic_and_subtopic_page_change_dicts:
            if change['cmd'] == (
                    subtopic_page_domain.CMD_UPDATE_SUBTOPIC_PAGE_PROPERTY):
                topic_and_subtopic_page_change_list.append(
                    subtopic_page_domain.SubtopicPageChange(change))
            else:
                topic_and_subtopic_page_change_list.append(
                    topic_domain.TopicChange(change))
        try:
            topic_services.update_topic_and_subtopic_pages(
                self.user_id, topic_id, topic_and_subtopic_page_change_list,
                commit_message)
        except utils.ValidationError as e:
            raise self.InvalidInputException(e)

        topic = topic_services.get_topic_by_id(topic_id, strict=False)
        skill_ids = topic.get_all_skill_ids()

        skill_id_to_description_dict = (
            skill_services.get_skill_descriptions_by_ids(topic_id, skill_ids))

        self.values.update({
            'topic_dict':
            topic.to_dict(),
            'skill_id_to_description_dict':
            skill_id_to_description_dict
        })

        self.render_json(self.values)
Example #20
0
    def test_save_topic_with_invalid_change_list(self):
        topic = topic_services.get_topic_by_id(self.TOPIC_ID)

        with self.assertRaisesRegexp(
            Exception, 'Unexpected error: received an invalid change list when'
            ' trying to save topic %s: %s' % (self.TOPIC_ID, None)):
            topic_services._save_topic('committer_id', topic,
                'commit_message', None)
Example #21
0
 def test_delete_topic(self):
     # Test whether an admin can delete a topic.
     topic_services.delete_topic(self.user_id_admin, self.TOPIC_ID)
     self.assertEqual(
         topic_services.get_topic_by_id(self.TOPIC_ID, strict=False), None)
     self.assertEqual(
         topic_services.get_topic_summary_by_id(self.TOPIC_ID,
                                                strict=False), None)
Example #22
0
    def delete(self, topic_id):
        """Handles Delete requests."""
        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)
Example #23
0
 def test_delete_topic(self):
     # Test whether an admin can delete a topic.
     topic_services.delete_topic(self.user_id_admin, self.TOPIC_ID)
     self.assertIsNone(
         topic_services.get_topic_by_id(self.TOPIC_ID, strict=False))
     self.assertIsNone(
         topic_services.get_topic_summary_by_id(self.TOPIC_ID, strict=False))
     self.assertIsNone(
         subtopic_page_services.get_subtopic_page_by_id(
             self.TOPIC_ID, 1, strict=False))
Example #24
0
    def test_update_topic(self):
        topic_services.assign_role(self.user_admin, self.user_a,
                                   topic_domain.ROLE_MANAGER, self.TOPIC_ID)

        # Test whether an admin can edit a topic.
        changelist = [
            topic_domain.TopicChange({
                'cmd': topic_domain.CMD_UPDATE_TOPIC_PROPERTY,
                'property_name': topic_domain.TOPIC_PROPERTY_DESCRIPTION,
                'old_value': 'Description',
                'new_value': 'New Description'
            })
        ]
        topic_services.update_topic_and_subtopic_pages(self.user_id_admin,
                                                       self.TOPIC_ID,
                                                       changelist,
                                                       'Updated Description.')
        topic = topic_services.get_topic_by_id(self.TOPIC_ID)
        topic_summary = topic_services.get_topic_summary_by_id(self.TOPIC_ID)
        self.assertEqual(topic.description, 'New Description')
        self.assertEqual(topic.version, 3)
        self.assertEqual(topic_summary.version, 3)

        # Test whether a topic_manager can edit a topic.
        changelist = [
            topic_domain.TopicChange({
                'cmd': topic_domain.CMD_UPDATE_TOPIC_PROPERTY,
                'property_name': topic_domain.TOPIC_PROPERTY_NAME,
                'old_value': 'Name',
                'new_value': 'New Name'
            })
        ]
        topic_services.update_topic_and_subtopic_pages(self.user_id_a,
                                                       self.TOPIC_ID,
                                                       changelist,
                                                       'Updated Name.')
        topic = topic_services.get_topic_by_id(self.TOPIC_ID)
        topic_summary = topic_services.get_topic_summary_by_id(self.TOPIC_ID)
        self.assertEqual(topic.name, 'New Name')
        self.assertEqual(topic.version, 4)
        self.assertEqual(topic_summary.name, 'New Name')
        self.assertEqual(topic_summary.version, 4)
Example #25
0
    def delete(self, topic_id):
        """Handles Delete requests."""
        if not feconf.ENABLE_NEW_STRUCTURES:
            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)
Example #26
0
    def test_update_subtopic_property(self):
        topic = topic_services.get_topic_by_id(self.TOPIC_ID)

        self.assertEqual(len(topic.subtopics), 1)
        self.assertEqual(topic.subtopics[0].title, 'Title')

        changelist = [topic_domain.TopicChange({
            'cmd': topic_domain.CMD_UPDATE_SUBTOPIC_PROPERTY,
            'property_name': 'title',
            'subtopic_id': 1,
            'old_value': 'Title',
            'new_value': 'New Title'
        })]
        topic_services.update_topic_and_subtopic_pages(
            self.user_id_admin, self.TOPIC_ID, changelist,
            'Update title of subtopic.')
        topic = topic_services.get_topic_by_id(self.TOPIC_ID)

        self.assertEqual(len(topic.subtopics), 1)
        self.assertEqual(topic.subtopics[0].title, 'New Title')
Example #27
0
    def test_get_topic_by_version(self):
        topic_id = topic_services.get_new_topic_id()
        self.save_new_topic(
            topic_id, self.user_id, 'topic name', 'Description',
            [], [], [], [], 1)

        changelist = [topic_domain.TopicChange({
            'cmd': topic_domain.CMD_UPDATE_TOPIC_PROPERTY,
            'property_name': topic_domain.TOPIC_PROPERTY_LANGUAGE_CODE,
            'old_value': 'en',
            'new_value': 'bn'
        })]
        topic_services.update_topic_and_subtopic_pages(
            self.user_id, topic_id, changelist, 'Change language code')

        topic_v0 = topic_services.get_topic_by_id(topic_id, version=0)
        topic_v1 = topic_services.get_topic_by_id(topic_id, version=1)

        self.assertEqual(topic_v1.language_code, 'en')
        self.assertEqual(topic_v0.language_code, 'bn')
Example #28
0
    def test_topic_creation(self):
        self.login(self.ADMIN_EMAIL)
        csrf_token = self._get_csrf_token_for_put()

        json_response = self.post_json(
            self.url, {'name': 'Topic name'}, csrf_token=csrf_token)
        topic_id = json_response['topicId']
        self.assertEqual(len(topic_id), 12)
        self.assertIsNotNone(
            topic_services.get_topic_by_id(topic_id, strict=False))
        self.logout()
Example #29
0
 def test_delete_skill(self):
     topic_services.delete_skill(self.user_id_admin, self.TOPIC_ID,
                                 self.skill_id)
     topic = topic_services.get_topic_by_id(self.TOPIC_ID)
     self.assertEqual(topic.skill_ids, [])
     topic_commit_log_entry = (
         topic_models.TopicCommitLogEntryModel.get_commit(self.TOPIC_ID, 2))
     self.assertEqual(topic_commit_log_entry.commit_type, 'edit')
     self.assertEqual(topic_commit_log_entry.topic_id, self.TOPIC_ID)
     self.assertEqual(topic_commit_log_entry.user_id, self.user_id_admin)
     self.assertEqual(topic_commit_log_entry.commit_message,
                      'Removed %s from skill ids' % self.skill_id)
Example #30
0
    def test_topic_creation(self):
        self.login(self.ADMIN_EMAIL)
        with self.swap(constants, 'ENABLE_NEW_STRUCTURE_EDITORS', True):
            csrf_token = self._get_csrf_token_for_put()

            json_response = self.post_json(self.url, {'name': 'Topic name'},
                                           csrf_token=csrf_token)
            topic_id = json_response['topicId']
            self.assertEqual(len(topic_id), 12)
            self.assertIsNotNone(
                topic_services.get_topic_by_id(topic_id, strict=False))
        self.logout()