def test_create_question_skill_link_increments_question_count(self): opportunity_services.create_skill_opportunity( self.SKILL_ID, 'description') self.save_new_question( self.QUESTION_ID, self.USER_ID, self._create_valid_question_data('ABC'), [self.SKILL_ID]) question_services.create_new_question_skill_link( self.USER_ID, self.QUESTION_ID, self.SKILL_ID, 0.3) skill_opportunities, _, _ = ( opportunity_services.get_skill_opportunities(None)) opportunity = skill_opportunities[0] self.assertEqual(opportunity.question_count, 1)
def test_create_skill_opportunity_counts_existing_linked_questions(self): self.save_new_question(self.QUESTION_ID, self.USER_ID, self._create_valid_question_data('ABC'), [self.SKILL_ID]) question_services.create_new_question_skill_link( self.USER_ID, self.QUESTION_ID, self.SKILL_ID, 0.3) opportunity_services.create_skill_opportunity(self.SKILL_ID, 'description') skill_opportunities, _, _ = ( opportunity_services.get_skill_opportunities(None)) self.assertEqual(len(skill_opportunities), 1) opportunity = skill_opportunities[0] self.assertEqual(opportunity.id, self.SKILL_ID) self.assertEqual(opportunity.skill_description, 'description') self.assertEqual(opportunity.question_count, 1)
def _create_skill(committer_id, skill, commit_message, commit_cmds): """Creates a new skill. Args: committer_id: str. ID of the committer. skill: Skill. The skill domain object. commit_message: str. A description of changes made to the skill. commit_cmds: list(SkillChange). A list of change commands made to the given skill. """ skill.validate() create_new_skill_rights(skill.id, committer_id) model = skill_models.SkillModel( id=skill.id, description=skill.description, language_code=skill.language_code, misconceptions=[ misconception.to_dict() for misconception in skill.misconceptions ], rubrics=[ rubric.to_dict() for rubric in skill.rubrics ], skill_contents=skill.skill_contents.to_dict(), next_misconception_id=skill.next_misconception_id, misconceptions_schema_version=skill.misconceptions_schema_version, rubric_schema_version=skill.rubric_schema_version, skill_contents_schema_version=skill.skill_contents_schema_version, superseding_skill_id=skill.superseding_skill_id, all_questions_merged=skill.all_questions_merged ) commit_cmd_dicts = [commit_cmd.to_dict() for commit_cmd in commit_cmds] model.commit(committer_id, commit_message, commit_cmd_dicts) skill.version += 1 create_skill_summary(skill.id) opportunity_services.create_skill_opportunity( skill_id=skill.id, skill_description=skill.description)
def map(skill_model): if skill_model.deleted: return opportunity_services.create_skill_opportunity(skill_model.id, skill_model.description) yield ('SUCCESS', skill_model.id)