Exemple #1
0
    def test_get_skill_from_model_with_invalid_skill_contents_schema_version(
        self
    ) -> None:
        commit_cmd = skill_domain.SkillChange({
            'cmd': skill_domain.CMD_CREATE_NEW
        })
        model = skill_models.SkillModel(
            id='skill_id',
            description='description',
            language_code='en',
            misconceptions=[],
            rubrics=[],
            next_misconception_id=0,
            misconceptions_schema_version=1,
            rubric_schema_version=1,
            skill_contents_schema_version=0,
            all_questions_merged=False
        )
        commit_cmd_dicts = [commit_cmd.to_dict()]
        model.commit(
            self.user_id_admin, 'skill model created', commit_cmd_dicts)

        with self.assertRaisesRegex(  # type: ignore[no-untyped-call]
            Exception,
            'Sorry, we can only process v1-v%d skill schemas at '
            'present.' % feconf.CURRENT_SKILL_CONTENTS_SCHEMA_VERSION):
            skill_fetchers.get_skill_from_model(model)
Exemple #2
0
    def test_get_skill_from_model_with_invalid_rubric_schema_version(
        self
    ) -> None:
        commit_cmd = skill_domain.SkillChange({
            'cmd': skill_domain.CMD_CREATE_NEW
        })
        example_1 = skill_domain.WorkedExample(
            state_domain.SubtitledHtml('2', '<p>Example Question 1</p>'),
            state_domain.SubtitledHtml('3', '<p>Example Explanation 1</p>')
        )
        model = skill_models.SkillModel(
            id='skill_id',
            description='description',
            language_code='en',
            misconceptions=[],
            rubrics=[],
            next_misconception_id=0,
            misconceptions_schema_version=2,
            rubric_schema_version=0,
            skill_contents_schema_version=2,
            all_questions_merged=False,
            skill_contents=skill_domain.SkillContents(  # type: ignore[no-untyped-call]
                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': {}
                    }
                })
            ).to_dict()
        )
        commit_cmd_dicts = [commit_cmd.to_dict()]
        model.commit(
            self.user_id_admin, 'skill model created', commit_cmd_dicts)

        with self.assertRaisesRegex(  # type: ignore[no-untyped-call]
            Exception,
            'Sorry, we can only process v1-v%d rubric schemas at '
            'present.' % feconf.CURRENT_RUBRIC_SCHEMA_VERSION):
            skill_fetchers.get_skill_from_model(model)
Exemple #3
0
    def test_get_skill_from_model_with_latest_schemas_version(self) -> None:
        commit_cmd = skill_domain.SkillChange({
            'cmd': skill_domain.CMD_CREATE_NEW
        })
        example_1 = skill_domain.WorkedExample(
            state_domain.SubtitledHtml('2', '<p>Example Question 1</p>'),
            state_domain.SubtitledHtml('3', '<p>Example Explanation 1</p>')
        )
        model = skill_models.SkillModel(
            id='skill_id',
            description='description',
            language_code='en',
            misconceptions=[],
            rubrics=[],
            next_misconception_id=0,
            misconceptions_schema_version=2,
            rubric_schema_version=2,
            skill_contents_schema_version=2,
            all_questions_merged=False,
            skill_contents=skill_domain.SkillContents(  # type: ignore[no-untyped-call]
                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': {}
                    }
                })
            ).to_dict()
        )
        commit_cmd_dicts = [commit_cmd.to_dict()]
        model.commit(
            self.user_id_admin, 'skill model created', commit_cmd_dicts)

        skill = skill_fetchers.get_skill_from_model(model)
        self.assertEqual(
            skill.misconceptions_schema_version,
            feconf.CURRENT_MISCONCEPTIONS_SCHEMA_VERSION
        )
        self.assertEqual(
            skill.skill_contents_schema_version,
            feconf.CURRENT_SKILL_CONTENTS_SCHEMA_VERSION
        )
        self.assertEqual(
            skill.rubric_schema_version,
            feconf.CURRENT_RUBRIC_SCHEMA_VERSION
        )
Exemple #4
0
    def _validate_question_count(cls, item,
                                 field_name_to_external_model_references):
        """Validate that question_count matches the number of questions linked
        to the opportunity's skill.

        Args:
            item: ndb.Model. SkillOpportunityModel to validate.
            field_name_to_external_model_references:
                dict(str, (list(base_model_validators.ExternalModelReference))).
                A dict keyed by field name. The field name represents
                a unique identifier provided by the storage
                model to which the external model is associated. Each value
                contains a list of ExternalModelReference objects corresponding
                to the field_name. For examples, all the external Exploration
                Models corresponding to a storage model can be associated
                with the field name 'exp_ids'. This dict is used for
                validation of External Model properties linked to the
                storage model.
        """
        skill_model_references = (
            field_name_to_external_model_references['skill_ids'])

        for skill_model_reference in skill_model_references:
            skill_model = skill_model_reference.model_instance
            if skill_model is None or skill_model.deleted:
                model_class = skill_model_reference.model_class
                model_id = skill_model_reference.model_id
                cls._add_error(
                    'skill_ids %s' %
                    (base_model_validators.ERROR_CATEGORY_FIELD_CHECK),
                    'Entity id %s: based on field skill_ids having'
                    ' value %s, expect model %s with id %s but it doesn\'t'
                    ' exist' %
                    (item.id, model_id, model_class.__name__, model_id))
                continue
            skill = skill_fetchers.get_skill_from_model(skill_model)
            question_skill_links = (
                question_services.get_question_skill_links_of_skill(
                    skill.id, skill.description))
            question_count = len(question_skill_links)
            if question_count != item.question_count:
                cls._add_error(
                    'question_%s' %
                    (base_model_validators.ERROR_CATEGORY_COUNT_CHECK),
                    'Entity id %s: question_count: %s does not match the '
                    'question_count of external skill model: %s' %
                    (item.id, item.question_count, question_count))
Exemple #5
0
    def _migrate_skill(
        skill_id: str, skill_model: skill_models.SkillModel
    ) -> result.Result[Tuple[str, skill_domain.Skill], Tuple[str, Exception]]:
        """Migrates skill and transform skill model into skill object.

        Args:
            skill_id: str. The id of the skill.
            skill_model: SkillModel. The skill model to migrate.

        Returns:
            Result((str, Skill), (str, Exception)). Result containing tuple that
            consists of skill ID and either skill object or Exception. Skill
            object is returned when the migration was successful and Exception
            is returned otherwise.
        """
        try:
            skill = skill_fetchers.get_skill_from_model(skill_model)
            skill.validate()
        except Exception as e:
            logging.exception(e)
            return result.Err((skill_id, e))

        return result.Ok((skill_id, skill))
Exemple #6
0
 def _get_model_domain_object_instance(cls, item):
     return skill_fetchers.get_skill_from_model(item)