Пример #1
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
     )
Пример #2
0
def get_skill_from_model(skill_model):
    """Returns a skill domain object given a skill model loaded
    from the datastore.

    Args:
        skill_model: SkillModel. The skill model loaded from the
            datastore.

    Returns:
        skill. A Skill domain object corresponding to the given
        skill model.
    """

    # Ensure the original skill model does not get altered.
    versioned_skill_contents = {
        'schema_version': skill_model.skill_contents_schema_version,
        'skill_contents': copy.deepcopy(skill_model.skill_contents)
    }

    versioned_misconceptions = {
        'schema_version': skill_model.misconceptions_schema_version,
        'misconceptions': copy.deepcopy(skill_model.misconceptions)
    }

    versioned_rubrics = {
        'schema_version': skill_model.rubric_schema_version,
        'rubrics': copy.deepcopy(skill_model.rubrics)
    }

    # Migrate the skill if it is not using the latest schema version.
    if (skill_model.skill_contents_schema_version !=
            feconf.CURRENT_SKILL_CONTENTS_SCHEMA_VERSION):
        _migrate_skill_contents_to_latest_schema(versioned_skill_contents)

    if (skill_model.misconceptions_schema_version !=
            feconf.CURRENT_MISCONCEPTIONS_SCHEMA_VERSION):
        _migrate_misconceptions_to_latest_schema(versioned_misconceptions)

    if (skill_model.rubric_schema_version !=
            feconf.CURRENT_RUBRIC_SCHEMA_VERSION):
        _migrate_rubrics_to_latest_schema(versioned_rubrics)

    return skill_domain.Skill(
        skill_model.id, skill_model.description,
        [
            skill_domain.Misconception.from_dict(misconception)
            for misconception in versioned_misconceptions['misconceptions']
        ], [
            skill_domain.Rubric.from_dict(rubric)
            for rubric in versioned_rubrics['rubrics']
        ], skill_domain.SkillContents.from_dict(
            versioned_skill_contents['skill_contents']),
        versioned_misconceptions['schema_version'],
        versioned_rubrics['schema_version'],
        versioned_skill_contents['schema_version'],
        skill_model.language_code,
        skill_model.version, skill_model.next_misconception_id,
        skill_model.superseding_skill_id, skill_model.all_questions_merged,
        skill_model.prerequisite_skill_ids, skill_model.created_on,
        skill_model.last_updated)
Пример #3
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
     )
Пример #4
0
def get_skill_from_model(skill_model, run_conversion=True):
    """Returns a skill domain object given a skill model loaded
    from the datastore.

    Args:
        skill_model: SkillModel. The skill model loaded from the
            datastore.
        run_conversion: bool. If true, the the skill's schema version will
            be checked against the current schema version. If they do not match,
            the skill will be automatically updated to the latest schema
            version.

    Returns:
        skill. A Skill domain object corresponding to the given
        skill model.
    """

    # Ensure the original skill model does not get altered.
    versioned_skill_contents = {
        'schema_version': skill_model.skill_contents_schema_version,
        'skill_contents': copy.deepcopy(skill_model.skill_contents)
    }

    versioned_misconceptions = {
        'schema_version': skill_model.misconceptions_schema_version,
        'misconceptions': copy.deepcopy(skill_model.misconceptions)
    }

    # Migrate the skill if it is not using the latest schema version.
    if (run_conversion and skill_model.skill_contents_schema_version !=
            feconf.CURRENT_SKILL_CONTENTS_SCHEMA_VERSION):
        _migrate_skill_contents_to_latest_schema(versioned_skill_contents)

    if (run_conversion and skill_model.misconceptions_schema_version !=
            feconf.CURRENT_MISCONCEPTIONS_SCHEMA_VERSION):
        _migrate_misconceptions_to_latest_schema(versioned_misconceptions)

    return skill_domain.Skill(
        skill_model.id, skill_model.description,
        [
            skill_domain.Misconception.from_dict(misconception)
            for misconception in versioned_misconceptions['misconceptions']
        ], skill_domain.SkillContents.from_dict(
            versioned_skill_contents['skill_contents']),
        versioned_misconceptions['schema_version'],
        versioned_skill_contents['schema_version'],
        skill_model.language_code,
        skill_model.version, skill_model.next_misconception_id,
        skill_model.superseding_skill_id, skill_model.all_questions_merged,
        skill_model.created_on, skill_model.last_updated)
Пример #5
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
     )
    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)