Exemplo n.º 1
0
    def setUp(self) -> None:
        super(SkillOpportunityModelTest, self).setUp()

        opportunity_models.SkillOpportunityModel(
            id='opportunity_id1',
            skill_description='A skill description',
            question_count=20,
        ).put()
        opportunity_models.SkillOpportunityModel(
            id='opportunity_id2',
            skill_description='A skill description',
            question_count=30,
        ).put()
Exemplo n.º 2
0
    def _create_skill_opportunity_model(
        skill: skill_models.SkillModel,
        question_skill_links: List[question_models.QuestionSkillLinkModel]
    ) -> result.Result[opportunity_models.SkillOpportunityModel, Exception]:
        """Transforms a skill object and a list of QuestionSkillLink objects
        into a skill opportunity model.

        Args:
            skill: skill_models.SkillModel. The skill to create the opportunity
                for.
            question_skill_links: list(question_models.QuestionSkillLinkModel).
                The list of QuestionSkillLinkModel for the given skill.

        Returns:
            Result[opportunity_models.SkillOpportunityModel, Exception].
            Result object that contains SkillOpportunityModel when the operation
            is successful and Exception when an exception occurs.
        """
        try:
            skill_opportunity = opportunity_domain.SkillOpportunity(
                skill_id=skill.id,
                skill_description=skill.description,
                question_count=(
                    GenerateSkillOpportunityModelJob.
                    _count_unique_question_ids(question_skill_links)))
            skill_opportunity.validate()
            with datastore_services.get_ndb_context():
                opportunity_model = opportunity_models.SkillOpportunityModel(
                    id=skill_opportunity.id,
                    skill_description=skill_opportunity.skill_description,
                    question_count=skill_opportunity.question_count)
                opportunity_model.update_timestamps()
                return result.Ok(opportunity_model)
        except Exception as e:
            return result.Err(e)