Esempio n. 1
0
 def test_misconception_id_validation(self):
     self.skill.misconceptions = [
         skill_domain.Misconception(
             self.MISCONCEPTION_ID, 'name', 'notes', 'default_feedback'),
         skill_domain.Misconception(
             self.MISCONCEPTION_ID, 'name 2', 'notes 2', 'default_feedback')]
     self._assert_validation_error('Duplicate misconception ID found')
Esempio n. 2
0
    def test_conversion_to_and_from_dict(self):
        """Test that to_dict and from_dict preserve all data within a
        skill_contents and misconception object.
        """
        skill_contents = skill_domain.SkillContents(
            state_domain.SubtitledHtml('1', 'Explanation'),
            [state_domain.SubtitledHtml('2', 'Example 1')], {
                '1': {},
                '2': {}
            },
            state_domain.WrittenTranslations.from_dict(
                {'translations_mapping': {
                    '1': {},
                    '2': {}
                }}))
        skill_contents_dict = skill_contents.to_dict()
        skill_contents_from_dict = skill_domain.SkillContents.from_dict(
            skill_contents_dict)

        misconceptions = skill_domain.Misconception(self.MISCONCEPTION_ID,
                                                    'Tag Name', 'Description',
                                                    'Feedback')
        misconceptions_dict = misconceptions.to_dict()
        misconceptions_from_dict = skill_domain.Misconception.from_dict(
            misconceptions_dict)
        self.assertEqual(skill_contents_from_dict.to_dict(),
                         skill_contents_dict)
        self.assertEqual(misconceptions_from_dict.to_dict(),
                         misconceptions_dict)
Esempio n. 3
0
    def setUp(self) -> None:
        super(SkillFetchersUnitTests, self).setUp()
        example_1 = skill_domain.WorkedExample(
            state_domain.SubtitledHtml('2', '<p>Example Question 1</p>'),
            state_domain.SubtitledHtml('3', '<p>Example Explanation 1</p>')
        )
        skill_contents = skill_domain.SkillContents(
            state_domain.SubtitledHtml('1', '<p>Explanation</p>'), [example_1],
            state_domain.RecordedVoiceovers.from_dict({
                'voiceovers_mapping': {
                    '1': {}, '2': {}, '3': {}
                }
            }),
            state_domain.WrittenTranslations.from_dict({
                'translations_mapping': {
                    '1': {}, '2': {}, '3': {}
                }
            })
        )
        misconceptions = [skill_domain.Misconception(
            self.MISCONCEPTION_ID_1, 'name', '<p>description</p>',
            '<p>default_feedback</p>', True)]
        self.skill_id = skill_services.get_new_skill_id()

        self.signup(self.CURRICULUM_ADMIN_EMAIL, self.CURRICULUM_ADMIN_USERNAME)
        self.user_id_admin = (
            self.get_user_id_from_email(self.CURRICULUM_ADMIN_EMAIL))  # type: ignore[no-untyped-call]
        self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME])  # type: ignore[no-untyped-call]

        self.skill = self.save_new_skill(  # type: ignore[no-untyped-call]
            self.skill_id, self.USER_ID, description='Description',
            misconceptions=misconceptions,
            skill_contents=skill_contents,
            prerequisite_skill_ids=['skill_id_1', 'skill_id_2'])
Esempio n. 4
0
 def setUp(self):
     super(SkillDomainUnitTests, self).setUp()
     skill_contents = skill_domain.SkillContents(
         state_domain.SubtitledHtml(
             '1', '<p>Explanation</p>'), [
                 state_domain.SubtitledHtml('2', '<p>Example 1</p>')],
         state_domain.RecordedVoiceovers.from_dict(
             {'voiceovers_mapping': {'1': {}, '2': {}}}),
         state_domain.WrittenTranslations.from_dict(
             {'translations_mapping': {'1': {}, '2': {}}}))
     misconceptions = [skill_domain.Misconception(
         self.MISCONCEPTION_ID, 'name', '<p>notes</p>',
         '<p>default_feedback</p>')]
     rubrics = [
         skill_domain.Rubric(
             constants.SKILL_DIFFICULTIES[0], '<p>Explanation 1</p>'),
         skill_domain.Rubric(
             constants.SKILL_DIFFICULTIES[1], '<p>Explanation 2</p>'),
         skill_domain.Rubric(
             constants.SKILL_DIFFICULTIES[2], '<p>Explanation 3</p>')]
     self.skill = skill_domain.Skill(
         self.SKILL_ID, 'Description', misconceptions, rubrics,
         skill_contents, feconf.CURRENT_MISCONCEPTIONS_SCHEMA_VERSION,
         feconf.CURRENT_RUBRIC_SCHEMA_VERSION,
         feconf.CURRENT_SKILL_CONTENTS_SCHEMA_VERSION, 'en', 0, 1,
         None, False
     )
Esempio n. 5
0
    def test_conversion_to_and_from_dict(self):
        """Test that to_dict and from_dict preserve all data within a
        skill_contents and misconception object.
        """
        skill_contents = skill_domain.SkillContents(
            state_domain.SubtitledHtml('1', '<p>Explanation</p>'), [
                state_domain.SubtitledHtml('2', '<p>Example 1</p>')],
            state_domain.RecordedVoiceovers.from_dict(
                {'voiceovers_mapping': {'1': {}, '2': {}}}),
            state_domain.WrittenTranslations.from_dict(
                {'translations_mapping': {'1': {}, '2': {}}}))
        skill_contents_dict = skill_contents.to_dict()
        skill_contents_from_dict = skill_domain.SkillContents.from_dict(
            skill_contents_dict)

        misconceptions = skill_domain.Misconception(
            self.MISCONCEPTION_ID, 'Tag Name', '<p>Description</p>',
            '<p>Feedback</p>')
        misconceptions_dict = misconceptions.to_dict()
        misconceptions_from_dict = skill_domain.Misconception.from_dict(
            misconceptions_dict)

        rubric = skill_domain.Rubric(
            constants.SKILL_DIFFICULTIES[0], '<p>Explanation</p>')
        rubric_dict = rubric.to_dict()
        rubric_from_dict = skill_domain.Rubric.from_dict(rubric_dict)
        self.assertEqual(
            skill_contents_from_dict.to_dict(), skill_contents_dict)
        self.assertEqual(
            misconceptions_from_dict.to_dict(), misconceptions_dict)
        self.assertEqual(
            rubric_from_dict.to_dict(), rubric_dict)
Esempio n. 6
0
    def setUp(self):
        super(SkillServicesUnitTests, self).setUp()
        skill_contents = skill_domain.SkillContents('Explanation',
                                                    ['Example 1'])
        misconceptions = [
            skill_domain.Misconception(self.MISCONCEPTION_ID_1, 'name',
                                       'description', 'default_feedback')
        ]
        self.SKILL_ID = skill_services.get_new_skill_id()

        self.signup('*****@*****.**', 'A')
        self.signup(self.ADMIN_EMAIL, username=self.ADMIN_USERNAME)
        self.signup('*****@*****.**', username='******')

        self.user_id_a = self.get_user_id_from_email('*****@*****.**')
        self.user_id_admin = self.get_user_id_from_email(self.ADMIN_EMAIL)
        self.user_id_admin_2 = self.get_user_id_from_email(
            '*****@*****.**')
        self.set_admins([self.ADMIN_USERNAME, 'adm2'])
        self.user_a = user_services.UserActionsInfo(self.user_id_a)
        self.user_admin = user_services.UserActionsInfo(self.user_id_admin)
        self.user_admin_2 = user_services.UserActionsInfo(self.user_id_admin_2)

        self.skill = self.save_new_skill(self.SKILL_ID,
                                         self.USER_ID,
                                         'Description',
                                         misconceptions=misconceptions,
                                         skill_contents=skill_contents)
    def setUp(self):
        super(SkillServicesUnitTests, self).setUp()
        skill_contents = skill_domain.SkillContents(
            state_domain.SubtitledHtml('1', '<p>Explanation</p>'), [
                state_domain.SubtitledHtml('2', '<p>Example 1</p>')],
            state_domain.RecordedVoiceovers.from_dict(
                {'voiceovers_mapping': {'1': {}, '2': {}}}),
            state_domain.WrittenTranslations.from_dict(
                {'translations_mapping': {'1': {}, '2': {}}}))
        misconceptions = [skill_domain.Misconception(
            self.MISCONCEPTION_ID_1, 'name', '<p>description</p>',
            '<p>default_feedback</p>', True)]
        self.SKILL_ID = skill_services.get_new_skill_id()

        self.signup('*****@*****.**', 'A')
        self.signup(self.ADMIN_EMAIL, username=self.ADMIN_USERNAME)
        self.signup('*****@*****.**', username='******')

        self.user_id_a = self.get_user_id_from_email('*****@*****.**')
        self.user_id_admin = self.get_user_id_from_email(self.ADMIN_EMAIL)
        self.user_id_admin_2 = self.get_user_id_from_email('*****@*****.**')
        self.set_admins([self.ADMIN_USERNAME, 'adm2'])
        self.user_a = user_services.UserActionsInfo(self.user_id_a)
        self.user_admin = user_services.UserActionsInfo(self.user_id_admin)
        self.user_admin_2 = user_services.UserActionsInfo(self.user_id_admin_2)

        self.skill = self.save_new_skill(
            self.SKILL_ID, self.USER_ID, description='Description',
            misconceptions=misconceptions,
            skill_contents=skill_contents,
            prerequisite_skill_ids=['skill_id_1', 'skill_id_2'])
Esempio n. 8
0
 def test_add_misconception(self):
     misconception = skill_domain.Misconception(
         self.MISCONCEPTION_ID + 1, 'name_2', '<p>notes_2</p>',
         '<p>default_feedback_2</p>', True)
     self.skill.add_misconception(misconception)
     self.skill.validate()
     self.assertEqual(self.skill.misconceptions[1], misconception)
Esempio n. 9
0
 def setUp(self):
     super(SkillServicesUnitTests, self).setUp()
     skill_contents = skill_domain.SkillContents(
         'Explanation', ['Example 1'])
     misconceptions = [skill_domain.Misconception(
         self.MISCONCEPTION_ID_1, 'name', 'description', 'default_feedback')]
     self.SKILL_ID = skill_services.get_new_skill_id()
     self.skill = self.save_new_skill(
         self.SKILL_ID, self.USER_ID, 'Description', misconceptions,
         skill_contents
     )
Esempio n. 10
0
 def setUp(self):
     super(SkillDomainUnitTests, self).setUp()
     skill_contents = skill_domain.SkillContents(
         'Explanation', ['Example 1'])
     misconceptions = [skill_domain.Misconception(
         self.MISCONCEPTION_ID, 'name', 'notes', 'default_feedback')]
     self.skill = skill_domain.Skill(
         self.SKILL_ID, 'Description', misconceptions,
         skill_contents, feconf.CURRENT_MISCONCEPTIONS_SCHEMA_VERSION,
         feconf.CURRENT_SKILL_CONTENTS_SCHEMA_VERSION, 'en', 0
     )
Esempio n. 11
0
 def setUp(self):
     super(SkillDomainUnitTests, self).setUp()
     skill_contents = skill_domain.SkillContents(
         state_domain.SubtitledHtml(
             '1', 'Explanation'), [
                 state_domain.SubtitledHtml('2', 'Example 1')], {})
     misconceptions = [skill_domain.Misconception(
         self.MISCONCEPTION_ID, 'name', 'notes', 'default_feedback')]
     self.skill = skill_domain.Skill(
         self.SKILL_ID, 'Description', misconceptions,
         skill_contents, feconf.CURRENT_MISCONCEPTIONS_SCHEMA_VERSION,
         feconf.CURRENT_SKILL_CONTENTS_SCHEMA_VERSION, 'en', 0, 1,
         None, False
     )
Esempio n. 12
0
    def test_migrate_misconceptions_to_latest_schema(self):
        skill_services.create_new_skill_rights('skill_id', 'user_id_admin')
        commit_cmd = skill_domain.SkillChange({
            'cmd': skill_domain.CMD_CREATE_NEW
        })
        explanation_content_id = feconf.DEFAULT_SKILL_EXPLANATION_CONTENT_ID
        skill_contents = skill_domain.SkillContents(
            state_domain.SubtitledHtml(
                explanation_content_id, feconf.DEFAULT_SKILL_EXPLANATION), [],
            state_domain.RecordedVoiceovers.from_dict({
                'voiceovers_mapping': {
                    explanation_content_id: {}
                }
            }),
            state_domain.WrittenTranslations.from_dict({
                'translations_mapping': {
                    explanation_content_id: {}
                }
            }))
        misconception = skill_domain.Misconception(
            1, 'name', 'description', 'default_feedback')
        model = skill_models.SkillModel(
            id='skill_id',
            description='description',
            language_code='en',
            misconceptions=[misconception.to_dict()],
            rubrics=[],
            skill_contents=skill_contents.to_dict(),
            next_misconception_id=1,
            misconceptions_schema_version=1,
            rubric_schema_version=1,
            skill_contents_schema_version=1,
            all_questions_merged=False
        )
        commit_cmd_dicts = [commit_cmd.to_dict()]
        model.commit(
            'user_id_admin', 'skill model created', commit_cmd_dicts)

        swap_skill_object = self.swap(skill_domain, 'Skill', MockSkillObject)
        current_schema_version_swap = self.swap(
            feconf, 'CURRENT_MISCONCEPTIONS_SCHEMA_VERSION', 2)

        with swap_skill_object, current_schema_version_swap:
            skill = skill_services.get_skill_from_model(model)

        self.assertEqual(skill.misconceptions_schema_version, 2)
Esempio n. 13
0
    def test_conversion_to_and_from_dict(self):
        """Test that to_dict and from_dict preserve all data within a
        skill_contents and misconception object.
        """
        skill_contents = skill_domain.SkillContents(
            'Explanation', ['example_1'])
        skill_contents_dict = skill_contents.to_dict()
        skill_contents_from_dict = skill_domain.SkillContents.from_dict(
            skill_contents_dict)

        misconceptions = skill_domain.Misconception(
            self.MISCONCEPTION_ID, 'Tag Name', 'Description', 'Feedback')
        misconceptions_dict = misconceptions.to_dict()
        misconceptions_from_dict = skill_domain.Misconception.from_dict(
            misconceptions_dict)
        self.assertEqual(
            skill_contents_from_dict.to_dict(), skill_contents_dict)
        self.assertEqual(
            misconceptions_from_dict.to_dict(), misconceptions_dict)
    def test_job_when_skills_have_math_rich_text_components_with_svgs(self):
        valid_html_1 = (
            '<oppia-noninteractive-math math_content-with-value="{&amp;q'
            'uot;raw_latex&amp;quot;: &amp;quot;(x - a_1)(x - a_2)(x - a'
            '_3)...(x - a_n-1)(x - a_n)&amp;quot;, &amp;quot;svg_filenam'
            'e&amp;quot;: &amp;quot;file1.svg&amp;quot;}"></oppia-noninte'
            'ractive-math>'
        )
        valid_html_2 = (
            '<oppia-noninteractive-math math_content-with-value="{&amp;'
            'quot;raw_latex&amp;quot;: &amp;quot;+,+,+,+&amp;quot;, &amp;'
            'quot;svg_filename&amp;quot;: &amp;quot;file2.svg&amp;quot;}">'
            '</oppia-noninteractive-math>'
        )

        example_1 = skill_domain.WorkedExample(
            state_domain.SubtitledHtml('2', valid_html_1),
            state_domain.SubtitledHtml('3', '<p>Example Explanation 1</p>')
        )
        skill_contents1 = skill_domain.SkillContents(
            state_domain.SubtitledHtml(
                '1', '<p>Explanation</p>'), [example_1],
            state_domain.RecordedVoiceovers.from_dict({
                'voiceovers_mapping': {
                    '1': {}, '2': {}, '3': {}
                }
            }),
            state_domain.WrittenTranslations.from_dict({
                'translations_mapping': {
                    '1': {}, '2': {}, '3': {}
                }
            })
        )
        misconceptions1 = [skill_domain.Misconception(
            0, 'name', '<p>misconception html1</p>',
            '<p>misconception html2</p>', True)]
        rubrics1 = [
            skill_domain.Rubric(
                constants.SKILL_DIFFICULTIES[0], [valid_html_2]),
            skill_domain.Rubric(
                constants.SKILL_DIFFICULTIES[1], ['<p>Explanation 2</p>']),
            skill_domain.Rubric(
                constants.SKILL_DIFFICULTIES[2], ['<p>Explanation 3</p>'])]
        skill1 = skill_domain.Skill(
            'skill_id1', 'Description', misconceptions1, rubrics1,
            skill_contents1, feconf.CURRENT_MISCONCEPTIONS_SCHEMA_VERSION,
            feconf.CURRENT_RUBRIC_SCHEMA_VERSION,
            feconf.CURRENT_SKILL_CONTENTS_SCHEMA_VERSION, 'en', 0, 1,
            None, False, ['skill_id_2']
        )
        skill_services.save_new_skill(self.albert_id, skill1)
        job_id = (
            skill_jobs_one_off.SkillMathRteAuditOneOffJob.create_new())
        skill_jobs_one_off.SkillMathRteAuditOneOffJob.enqueue(job_id)
        self.process_and_flush_pending_tasks()

        output = skill_jobs_one_off.SkillMathRteAuditOneOffJob.get_output(
            job_id)
        overall_result = ast.literal_eval(output[0])
        expected_skill1_info = {
            'skill_id': 'skill_id1',
            'latex_strings_with_svg': [
                '(x - a_1)(x - a_2)(x - a_3)...(x - a_n-1)(x - a_n)', '+,+,+,+']
        }
        skill_latex_info = overall_result[1]
        self.assertEqual(skill_latex_info[0], expected_skill1_info)