def test_get_multi_skills(self): self.save_new_skill('skill_a', self.user_id_admin, 'Description A', misconceptions=[], skill_contents=skill_domain.SkillContents( state_domain.SubtitledHtml('1', 'Explanation'), [state_domain.SubtitledHtml('2', 'Example 1')], {})) self.save_new_skill('skill_b', self.user_id_admin, 'Description B', misconceptions=[], skill_contents=skill_domain.SkillContents( state_domain.SubtitledHtml('1', 'Explanation'), [state_domain.SubtitledHtml('2', 'Example 1')], {})) try: skill_services.get_multi_skills(['skill_a', 'skill_b']) except Exception: self.fail(msg='Unexpected exception raised.') with self.assertRaisesRegexp(Exception, 'No skill exists for ID skill_c'): skill_services.get_multi_skills(['skill_a', 'skill_c'])
def test_get_multi_skills(self): example_1 = skill_domain.WorkedExample( state_domain.SubtitledHtml('2', '<p>Example Question 1</p>'), state_domain.SubtitledHtml('3', '<p>Example Explanation 1</p>')) self.save_new_skill( 'skill_a', self.user_id_admin, description='Description A', misconceptions=[], 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': {} }}))) self.save_new_skill( 'skill_b', self.user_id_admin, description='Description B', misconceptions=[], 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': {} }}))) skills = skill_fetchers.get_multi_skills(['skill_a', 'skill_b']) self.assertEqual(len(skills), 2) self.assertEqual(skills[0].id, 'skill_a') self.assertEqual(skills[0].description, 'Description A') self.assertEqual(skills[0].misconceptions, []) self.assertEqual(skills[1].id, 'skill_b') self.assertEqual(skills[1].description, 'Description B') self.assertEqual(skills[1].misconceptions, []) with self.assertRaisesRegexp(Exception, 'No skill exists for ID skill_c'): skill_fetchers.get_multi_skills(['skill_a', 'skill_c'])
def test_get_unpublished_skill_rights_by_creator(self): self.save_new_skill('skill_a', self.user_id_admin, 'Description A', misconceptions=[], skill_contents=skill_domain.SkillContents( state_domain.SubtitledHtml('1', 'Explanation'), [state_domain.SubtitledHtml('2', 'Example 1')], {})) self.save_new_skill('skill_b', self.user_id_admin, 'Description B', misconceptions=[], skill_contents=skill_domain.SkillContents( state_domain.SubtitledHtml('1', 'Explanation'), [state_domain.SubtitledHtml('2', 'Example 1')], {})) skill_rights = skill_services.get_unpublished_skill_rights_by_creator( self.user_id_admin) skill_ids = [skill_rights_obj.id for skill_rights_obj in skill_rights] self.assertListEqual(skill_ids, ['skill_a', 'skill_b']) skill_services.publish_skill(self.SKILL_ID, self.user_id_admin) skill_rights = skill_services.get_unpublished_skill_rights_by_creator( self.user_id_admin) skill_ids = [skill_rights_obj.id for skill_rights_obj in skill_rights] self.assertListEqual(skill_ids, ['skill_a', 'skill_b'])
def test_get_descriptions_of_skills(self): self.save_new_skill( 'skill_id_1', self.user_id_admin, description='Description 1', misconceptions=[], 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': {}}}))) self.save_new_skill( 'skill_id_2', self.user_id_admin, description='Description 2', misconceptions=[], 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_services.delete_skill(self.user_id_admin, 'skill_id_2') skill_descriptions, deleted_skill_ids = ( skill_services.get_descriptions_of_skills( ['skill_id_1', 'skill_id_2'])) self.assertEqual(deleted_skill_ids, ['skill_id_2']) self.assertEqual( skill_descriptions, { 'skill_id_1': 'Description 1', 'skill_id_2': None } )
def test_get_skill_descriptions_by_ids(self): self.save_new_skill('skill_2', self.USER_ID, 'Description 2', misconceptions=[], skill_contents=skill_domain.SkillContents( 'Explanation', ['Example 1'])) self.save_new_skill('skill_3', self.USER_ID, 'Description 3', misconceptions=[], skill_contents=skill_domain.SkillContents( 'Explanation', ['Example 1'])) with self.swap(feconf, 'CAN_SEND_EMAILS', True): skill_descriptions = skill_services.get_skill_descriptions_by_ids( 'topic_id', [self.SKILL_ID, 'skill_2', 'skill_3']) messages = self.mail_stub.get_sent_messages( to=feconf.ADMIN_EMAIL_ADDRESS) self.assertEqual(len(messages), 0) skill_services.delete_skill(self.USER_ID, 'skill_2') skill_descriptions = skill_services.get_skill_descriptions_by_ids( 'topic_id', [self.SKILL_ID, 'skill_2', 'skill_3']) messages = self.mail_stub.get_sent_messages( to=feconf.ADMIN_EMAIL_ADDRESS) expected_email_html_body = ('The deleted skills: skill_2 are still' ' present in topic with id topic_id') self.assertEqual(len(messages), 1) self.assertIn(expected_email_html_body, messages[0].html.decode()) self.assertEqual( skill_descriptions, { self.SKILL_ID: 'Description', 'skill_2': None, 'skill_3': 'Description 3' })
def test_get_skill_descriptions_by_ids(self): self.save_new_skill( 'skill_2', self.USER_ID, 'Description 2', misconceptions=[], 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': {} }}))) self.save_new_skill( 'skill_3', self.USER_ID, 'Description 3', misconceptions=[], 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': {} }}))) with self.swap(feconf, 'CAN_SEND_EMAILS', True): skill_descriptions = skill_services.get_skill_descriptions_by_ids( 'topic_id', [self.SKILL_ID, 'skill_2', 'skill_3']) messages = self.mail_stub.get_sent_messages( to=feconf.ADMIN_EMAIL_ADDRESS) self.assertEqual(len(messages), 0) skill_services.delete_skill(self.USER_ID, 'skill_2') skill_descriptions = skill_services.get_skill_descriptions_by_ids( 'topic_id', [self.SKILL_ID, 'skill_2', 'skill_3']) messages = self.mail_stub.get_sent_messages( to=feconf.ADMIN_EMAIL_ADDRESS) expected_email_html_body = ('The deleted skills: skill_2 are still' ' present in topic with id topic_id') self.assertEqual(len(messages), 1) self.assertIn(expected_email_html_body, messages[0].html.decode()) self.assertEqual( skill_descriptions, { self.SKILL_ID: 'Description', 'skill_2': None, 'skill_3': 'Description 3' })
def test_get_unpublished_skill_rights_by_creator(self): self.save_new_skill( 'skill_a', self.user_id_admin, 'Description A', misconceptions=[], 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': {}}}))) self.save_new_skill( 'skill_b', self.user_id_admin, 'Description B', misconceptions=[], 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_rights = skill_services.get_unpublished_skill_rights_by_creator( self.user_id_admin) skill_ids = [skill_rights_obj.id for skill_rights_obj in skill_rights] self.assertListEqual(skill_ids, ['skill_a', 'skill_b']) skill_services.publish_skill(self.SKILL_ID, self.user_id_admin) skill_rights = skill_services.get_unpublished_skill_rights_by_creator( self.user_id_admin) skill_ids = [skill_rights_obj.id for skill_rights_obj in skill_rights] self.assertListEqual(skill_ids, ['skill_a', 'skill_b'])
def setUp(self): """Before each individual test, create a dummy skill.""" super(ConceptCardDataHandlerTest, self).setUp() self.signup(self.CURRICULUM_ADMIN_EMAIL, self.CURRICULUM_ADMIN_USERNAME) self.admin_id = self.get_user_id_from_email(self.CURRICULUM_ADMIN_EMAIL) self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME]) example_1 = skill_domain.WorkedExample( state_domain.SubtitledHtml('2', '<p>Example Question 1</p>'), state_domain.SubtitledHtml('3', '<p>Example Explanation 1</p>') ) example_2 = skill_domain.WorkedExample( state_domain.SubtitledHtml('4', '<p>Example Question 2</p>'), state_domain.SubtitledHtml('5', '<p>Example Explanation 2</p>') ) self.skill_contents = skill_domain.SkillContents( state_domain.SubtitledHtml( '1', '<p>Skill Explanation</p>'), [example_1, example_2], state_domain.RecordedVoiceovers.from_dict({ 'voiceovers_mapping': { '1': {}, '2': {}, '3': {}, '4': {}, '5': {} } }), state_domain.WrittenTranslations.from_dict({ 'translations_mapping': { '1': {}, '2': {}, '3': {}, '4': {}, '5': {} } }) ) self.skill_contents_1 = skill_domain.SkillContents( state_domain.SubtitledHtml( '1', '<p>Skill Explanation 1</p>'), [example_1, example_2], state_domain.RecordedVoiceovers.from_dict({ 'voiceovers_mapping': { '1': {}, '2': {}, '3': {}, '4': {}, '5': {} } }), state_domain.WrittenTranslations.from_dict({ 'translations_mapping': { '1': {}, '2': {}, '3': {}, '4': {}, '5': {} } }) ) self.admin = user_services.get_user_actions_info(self.admin_id) self.skill_id = skill_services.get_new_skill_id() self.save_new_skill( self.skill_id, self.admin_id, description='Description', skill_contents=self.skill_contents) self.skill_id_1 = skill_services.get_new_skill_id() self.save_new_skill( self.skill_id_1, self.admin_id, description='Description', skill_contents=self.skill_contents_1) self.skill_id_2 = skill_services.get_new_skill_id()
def test_get_rubrics_of_linked_skills(self): self.save_new_skill( 'skill_id_1', self.user_id_admin, 'Description 1', misconceptions=[], 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': {} }}))) self.save_new_skill( 'skill_id_2', self.user_id_admin, 'Description 2', misconceptions=[], 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_services.delete_skill(self.user_id_admin, 'skill_id_2') skill_rubrics, deleted_skill_ids = ( skill_services.get_rubrics_of_skills(['skill_id_1', 'skill_id_2'])) self.assertEqual(deleted_skill_ids, ['skill_id_2']) self.assertEqual( skill_rubrics, { 'skill_id_1': [ skill_domain.Rubric(constants.SKILL_DIFFICULTIES[0], 'Explanation 1').to_dict(), skill_domain.Rubric(constants.SKILL_DIFFICULTIES[1], 'Explanation 2').to_dict(), skill_domain.Rubric(constants.SKILL_DIFFICULTIES[2], 'Explanation 3').to_dict() ], 'skill_id_2': None })
def setUp(self): """Before each individual test, create a dummy skill.""" super(ConceptCardDataHandlerTest, self).setUp() self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.skill_contents = skill_domain.SkillContents( state_domain.SubtitledHtml('1', '<p>Skill Explanation</p>'), [ state_domain.SubtitledHtml('2', '<p>Example 1</p>'), state_domain.SubtitledHtml('3', '<p>Example 2</p>') ], state_domain.RecordedVoiceovers.from_dict( {'voiceovers_mapping': { '1': {}, '2': {}, '3': {} }}), state_domain.WrittenTranslations.from_dict( {'translations_mapping': { '1': {}, '2': {}, '3': {} }})) self.skill_contents_1 = skill_domain.SkillContents( state_domain.SubtitledHtml('1', '<p>Skill Explanation 1</p>'), [ state_domain.SubtitledHtml('2', '<p>Example 3</p>'), state_domain.SubtitledHtml('3', '<p>Example 4</p>') ], state_domain.RecordedVoiceovers.from_dict( {'voiceovers_mapping': { '1': {}, '2': {}, '3': {} }}), state_domain.WrittenTranslations.from_dict( {'translations_mapping': { '1': {}, '2': {}, '3': {} }})) self.admin = user_services.UserActionsInfo(self.admin_id) self.skill_id = skill_services.get_new_skill_id() self.save_new_skill(self.skill_id, self.admin_id, 'Description', skill_contents=self.skill_contents) self.skill_id_1 = skill_services.get_new_skill_id() self.save_new_skill(self.skill_id_1, self.admin_id, 'Description', skill_contents=self.skill_contents_1) self.skill_id_2 = skill_services.get_new_skill_id()
def test_get_multi_skills(self): self.save_new_skill('skill_a', self.user_id_admin, 'Description A', misconceptions=[], 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': {} } }))) self.save_new_skill('skill_b', self.user_id_admin, 'Description B', misconceptions=[], 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': {} } }))) skills = skill_services.get_multi_skills(['skill_a', 'skill_b']) self.assertEqual(len(skills), 2) self.assertEqual(skills[0].id, 'skill_a') self.assertEqual(skills[0].description, 'Description A') self.assertEqual(skills[0].misconceptions, []) self.assertEqual(skills[1].id, 'skill_b') self.assertEqual(skills[1].description, 'Description B') self.assertEqual(skills[1].misconceptions, []) with self.assertRaisesRegexp(Exception, 'No skill exists for ID skill_c'): skill_services.get_multi_skills(['skill_a', 'skill_c'])
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)
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 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)
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 )
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'])
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'])
def test_migrate_skill_contents_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), [], {explanation_content_id: {}}, state_domain.WrittenTranslations.from_dict( {'translations_mapping': { explanation_content_id: {} }})) model = skill_models.SkillModel( id='skill_id', description='description', language_code='en', misconceptions=[], skill_contents=skill_contents.to_dict(), next_misconception_id=1, misconceptions_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_SKILL_CONTENTS_SCHEMA_VERSION', 2) with swap_skill_object, current_schema_version_swap: skill = skill_services.get_skill_from_model(model) self.assertEqual(skill.skill_contents_schema_version, 2)
def test_fail_to_add_unpublished_skill_id(self): self.save_new_skill('skill_a', self.user_id_a, 'Description A', misconceptions=[], skill_contents=(skill_domain.SkillContents( 'Explanation', ['Example 1']))) with self.assertRaisesRegexp( Exception, 'Cannot assign unpublished skills to a topic'): self.topic.add_uncategorized_skill_id('skill_a')
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 )
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 )
def test_fail_to_add_unpublished_skill_id(self): self.save_new_skill( 'skill_a', self.user_id_a, 'Description A', misconceptions=[], skill_contents=skill_domain.SkillContents( state_domain.SubtitledHtml( '1', 'Explanation'), [ state_domain.SubtitledHtml('2', 'Example 1')], {'1': {}, '2': {}})) with self.assertRaisesRegexp( Exception, 'Cannot assign unpublished skills to a topic'): self.topic.add_uncategorized_skill_id('skill_a')
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 )
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_fail_to_add_unpublished_skill_id(self): self.save_new_skill( 'skill_a', self.user_id_a, 'Description A', misconceptions=[], skill_contents=skill_domain.SkillContents( state_domain.SubtitledHtml( '1', 'Explanation'), [ 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': {}}}))) with self.assertRaisesRegexp( Exception, 'Cannot assign unpublished skills to a topic'): self.topic.add_uncategorized_skill_id('skill_a')
def test_migrate_misconceptions_to_latest_schema(self): 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: {} } })) model = skill_models.SkillModel( id='skill_id', description='description', language_code='en', misconceptions=[{ 'id': 1, 'name': 'name', 'notes': 'notes', 'feedback': 'default_feedback' }], rubrics=[], skill_contents=skill_contents.to_dict(), next_misconception_id=2, 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) current_schema_version_swap = self.swap( feconf, 'CURRENT_MISCONCEPTIONS_SCHEMA_VERSION', 2) with current_schema_version_swap: skill = skill_services.get_skill_from_model(model) self.assertEqual(skill.misconceptions_schema_version, 2) self.assertEqual(skill.misconceptions[0].must_be_addressed, True)
def setUp(self): """Before each individual test, create a dummy skill.""" super(ConceptCardDataHandlerTest, self).setUp() self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.skill_contents = skill_domain.SkillContents( 'Skill Explanation', ['Example 1', 'Example 2']) self.admin = user_services.UserActionsInfo(self.admin_id) self.skill_id = skill_services.get_new_skill_id() self.save_new_skill( self.skill_id, self.admin_id, 'Description', skill_contents=self.skill_contents)
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)
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 setUp(self): super(SkillSummaryModelValidatorTests, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.set_admins([self.ADMIN_USERNAME]) rubrics = [ skill_domain.Rubric(constants.SKILL_DIFFICULTIES[0], ['Explanation 1']), skill_domain.Rubric(constants.SKILL_DIFFICULTIES[1], ['Explanation 2']), skill_domain.Rubric(constants.SKILL_DIFFICULTIES[2], ['Explanation 3']) ] language_codes = ['ar', 'en', 'en'] skills = [ skill_domain.Skill.create_default_skill('%s' % i, 'description %d' % i, rubrics) for i in python_utils.RANGE(3) ] 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': {} }})) misconception_dict = { 'id': 0, 'name': 'name', 'notes': '<p>notes</p>', 'feedback': '<p>default_feedback</p>', 'must_be_addressed': True } misconception = skill_domain.Misconception.from_dict( misconception_dict) for index, skill in enumerate(skills): skill.language_code = language_codes[index] skill.skill_contents = skill_contents skill.add_misconception(misconception) skill_services.save_new_skill(self.owner_id, skill) self.model_instance_0 = skill_models.SkillSummaryModel.get_by_id('0') self.model_instance_1 = skill_models.SkillSummaryModel.get_by_id('1') self.model_instance_2 = skill_models.SkillSummaryModel.get_by_id('2') self.job_class = ( prod_validation_jobs_one_off.SkillSummaryModelAuditOneOffJob)