def test_cannot_move_existing_skill_to_subtopic(self): self.topic.subtopics = [ topic_domain.Subtopic(1, 'Title', ['skill_id_1']), topic_domain.Subtopic(2, 'Another title', ['skill_id_1'])] with self.assertRaisesRegexp( Exception, 'Skill id skill_id_1 is already present in the target subtopic'): self.topic.move_skill_id_to_subtopic(1, 2, 'skill_id_1')
def setUp(self): """Completes the sign-up process for the various users.""" super(BasePracticeSessionsControllerTests, 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]) self.admin = user_services.get_user_actions_info(self.admin_id) self.topic_id = 'topic' self.topic_id_1 = 'topic1' self.skill_id1 = 'skill_id_1' self.skill_id2 = 'skill_id_2' self.save_new_skill(self.skill_id1, self.admin_id, description='Skill 1') self.save_new_skill(self.skill_id2, self.admin_id, description='Skill 2') self.topic = topic_domain.Topic.create_default_topic( self.topic_id, 'public_topic_name', 'public-topic-name', 'description', 'fragm') self.topic.subtopics.append( topic_domain.Subtopic( 1, 'subtopic_name', [self.skill_id1], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'subtopic-name-one')) self.topic.subtopics.append( topic_domain.Subtopic( 2, 'subtopic_name_2', [self.skill_id2], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'subtopic-name-two')) self.topic.next_subtopic_id = 3 self.topic.skill_ids_for_diagnostic_test = [self.skill_id1] self.topic.thumbnail_filename = 'Topic.svg' self.topic.thumbnail_bg_color = ( constants.ALLOWED_THUMBNAIL_BG_COLORS['topic'][0]) topic_services.save_new_topic(self.admin_id, self.topic) self.topic = topic_domain.Topic.create_default_topic( self.topic_id_1, 'private_topic_name', 'private-topic-name', 'description', 'fragm') self.topic.thumbnail_filename = 'Topic.svg' self.topic.thumbnail_bg_color = ( constants.ALLOWED_THUMBNAIL_BG_COLORS['topic'][0]) topic_services.save_new_topic(self.admin_id, self.topic) topic_services.publish_topic(self.topic_id, self.admin_id)
def setUp(self) -> None: super(SubtopicPageServicesUnitTests, self).setUp() self.signup(self.CURRICULUM_ADMIN_EMAIL, self.CURRICULUM_ADMIN_USERNAME) self.admin_id = self.get_user_id_from_email( # type: ignore[no-untyped-call] self.CURRICULUM_ADMIN_EMAIL) self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME ]) # type: ignore[no-untyped-call] self.TOPIC_ID = topic_fetchers.get_new_topic_id() self.subtopic_page = ( subtopic_page_domain.SubtopicPage.create_default_subtopic_page( self.subtopic_id, self.TOPIC_ID)) subtopic_page_services.save_subtopic_page( self.user_id, self.subtopic_page, 'Added subtopic', [ topic_domain.TopicChange({ 'cmd': topic_domain.CMD_ADD_SUBTOPIC, 'subtopic_id': 1, 'title': 'Sample', 'url_fragment': 'sample-fragment' }) ]) self.subtopic_page_id = ( subtopic_page_domain.SubtopicPage.get_subtopic_page_id( self.TOPIC_ID, 1)) self.TOPIC_ID_1 = topic_fetchers.get_new_topic_id() # Set up topic and subtopic. topic = topic_domain.Topic.create_default_topic( self.TOPIC_ID_1, 'Place Values', 'abbrev', 'description', 'fragm') topic.thumbnail_filename = 'thumbnail.svg' topic.thumbnail_bg_color = '#C6DCDA' topic.subtopics = [ topic_domain.Subtopic( 1, 'Naming Numbers', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-url'), topic_domain.Subtopic( 2, 'Subtopic Name', ['skill_id_2'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'other-subtopic-url') ] topic.next_subtopic_id = 3 topic.skill_ids_for_diagnostic_test = ['skill_id_1'] topic_services.save_new_topic(self.admin_id, topic) # type: ignore[no-untyped-call] # Publish the topic and its stories. topic_services.publish_topic( self.TOPIC_ID_1, self.admin_id) # type: ignore[no-untyped-call]
def test_cannot_move_existing_skill_to_subtopic(self): self.topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0]), topic_domain.Subtopic( 2, 'Another title', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0]) ] with self.assertRaisesRegexp( Exception, 'Skill id skill_id_1 is already present in the target subtopic' ): self.topic.move_skill_id_to_subtopic(1, 2, 'skill_id_1')
def setUp(self): """Completes the sign-up process for the various users.""" super(BaseTopicViewerControllerTests, 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.admin = user_services.UserActionsInfo(self.admin_id) self.topic_id = 'topic' self.story_id = 'story' self.topic_id_1 = 'topic1' self.story = story_domain.Story.create_default_story( self.story_id, 'story_title', self.topic_id_1) self.story.description = 'story_description' self.topic = topic_domain.Topic.create_default_topic( self.topic_id, 'public_topic_name') self.topic.uncategorized_skill_ids.append('skill_id_1') self.topic.subtopics.append( topic_domain.Subtopic(1, 'subtopic_name', ['skill_id_2'])) self.topic.next_subtopic_id = 2 self.topic.canonical_story_ids.append(self.story_id) topic_services.save_new_topic(self.admin_id, self.topic) story_services.save_new_story(self.admin_id, self.story) self.topic = topic_domain.Topic.create_default_topic( self.topic_id_1, 'private_topic_name') topic_services.save_new_topic(self.admin_id, self.topic) topic_services.publish_topic(self.topic_id, self.admin_id)
def test_get_all_topic_names(self): response = self.get_json('/getalltopicnames') self.assertEqual( response, {'topic_names': []} ) topic_id = '0' topic = topic_domain.Topic.create_default_topic( topic_id, 'topic', 'abbrev', 'description') topic.thumbnail_filename = 'thumbnail.svg' topic.thumbnail_bg_color = '#C6DCDA' topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_3'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-three')] topic.next_subtopic_id = 2 topic_services.save_new_topic(self.owner_id, topic) topic_services.publish_topic(topic_id, self.admin_id) response = self.get_json('/getalltopicnames') self.assertEqual( response, {'topic_names': ['topic']} )
def setUp(self): """Completes the sign-up process for the various users.""" super(BasePracticeSessionsControllerTests, 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.admin = user_services.UserActionsInfo(self.admin_id) self.topic_id = 'topic' self.topic_id_1 = 'topic1' self.skill_id1 = 'skill_id_1' self.skill_id2 = 'skill_id_2' self.save_new_skill(self.skill_id1, self.admin_id, description='Skill 1') self.save_new_skill(self.skill_id2, self.admin_id, description='Skill 2') self.topic = topic_domain.Topic.create_default_topic( self.topic_id, 'public_topic_name', 'abbrev') self.topic.uncategorized_skill_ids.append(self.skill_id1) self.topic.subtopics.append( topic_domain.Subtopic(1, 'subtopic_name', [self.skill_id2])) self.topic.next_subtopic_id = 2 topic_services.save_new_topic(self.admin_id, self.topic) self.topic = topic_domain.Topic.create_default_topic( self.topic_id_1, 'private_topic_name', 'abbrev') topic_services.save_new_topic(self.admin_id, self.topic) topic_services.publish_topic(self.topic_id, self.admin_id)
def test_get(self): self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.login(self.ADMIN_EMAIL, is_super_admin=True) topic_id_1 = topic_services.get_new_topic_id() topic_id_2 = topic_services.get_new_topic_id() private_topic = topic_domain.Topic.create_default_topic( topic_id_1, 'private_topic_name', 'private-topic-name', 'description') topic_services.save_new_topic(admin_id, private_topic) public_topic = topic_domain.Topic.create_default_topic( topic_id_2, 'public_topic_name', 'public-topic-name', 'description') public_topic.thumbnail_filename = 'Topic.svg' public_topic.thumbnail_bg_color = ( constants.ALLOWED_THUMBNAIL_BG_COLORS['topic'][0]) public_topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_1', 'skill_id_2', 'skill_id_3'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 'dummy-subtopic-three')] public_topic.next_subtopic_id = 2 topic_services.save_new_topic(admin_id, public_topic) topic_services.publish_topic(topic_id_2, admin_id) csrf_token = self.get_new_csrf_token() new_config_value = [{ 'name': 'math', 'topic_ids': [topic_id_1, topic_id_2], 'course_details': 'Course details for classroom.', 'topic_list_intro': 'Topics covered for classroom', 'url_fragment': 'math', }] payload = { 'action': 'save_config_properties', 'new_config_property_values': { config_domain.CLASSROOM_PAGES_DATA.name: ( new_config_value), } } self.post_json('/adminhandler', payload, csrf_token=csrf_token) self.logout() json_response = self.get_json( '%s/%s' % (feconf.CLASSROOM_DATA_HANDLER, 'math')) topic_summary_dict = ( topic_services.get_topic_summary_by_id(topic_id_2).to_dict()) expected_dict = { 'name': 'math', 'topic_summary_dicts': [topic_summary_dict], 'course_details': 'Course details for classroom.', 'topic_list_intro': 'Topics covered for classroom' } self.assertDictContainsSubset(expected_dict, json_response)
def setUp(self): super(OpportunityServicesUnitTest, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.CURRICULUM_ADMIN_EMAIL, self.CURRICULUM_ADMIN_USERNAME) self.admin_id = self.get_user_id_from_email(self.CURRICULUM_ADMIN_EMAIL) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME]) self.TOPIC_ID = 'topic' self.STORY_ID = 'story' explorations = [self.save_new_valid_exploration( '%s' % i, self.owner_id, title='title %d' % i, category='category%d' % i, end_state_name='End State', correctness_feedback_enabled=True ) for i in python_utils.RANGE(5)] for exp in explorations: self.publish_exploration(self.owner_id, exp.id) topic = topic_domain.Topic.create_default_topic( self.TOPIC_ID, 'topic', 'abbrev', 'description') topic.thumbnail_filename = 'thumbnail.svg' topic.thumbnail_bg_color = '#C6DCDA' topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-url')] topic.next_subtopic_id = 2 topic_services.save_new_topic(self.owner_id, topic) topic_services.publish_topic(self.TOPIC_ID, self.admin_id) story = story_domain.Story.create_default_story( self.STORY_ID, 'A story', 'Description', self.TOPIC_ID, 'story-two') story_services.save_new_story(self.owner_id, story) topic_services.add_canonical_story( self.owner_id, self.TOPIC_ID, self.STORY_ID) topic_services.publish_story( self.TOPIC_ID, self.STORY_ID, self.admin_id) story_services.update_story( self.owner_id, self.STORY_ID, [story_domain.StoryChange({ 'cmd': 'add_story_node', 'node_id': 'node_1', 'title': 'Node1', }), story_domain.StoryChange({ 'cmd': 'update_story_node_property', 'property_name': 'exploration_id', 'node_id': 'node_1', 'old_value': None, 'new_value': '0' })], 'Changes.')
def test_add_uncategorized_skill_id(self): self.topic.subtopics.append( topic_domain.Subtopic('id_2', 'Title2', ['skill_id_2'])) with self.assertRaisesRegexp( Exception, 'The skill id skill_id_1 already exists in subtopic with id 1'): self.topic.add_uncategorized_skill_id('skill_id_1') self.topic.add_uncategorized_skill_id('skill_id_3') self.assertEqual(self.topic.uncategorized_skill_ids, ['skill_id_3'])
def test_get_all_subtopics(self): self.topic.subtopics = [topic_domain.Subtopic( 1, 'Title', ['skill_id_1'])] subtopics = self.topic.get_all_subtopics() self.assertEqual( subtopics, [{ 'skill_ids': ['skill_id_1'], 'id': 1, 'title': 'Title'}])
def test_add_uncategorized_skill_id(self): self.topic.subtopics.append( topic_domain.Subtopic( 'id_2', 'Title2', ['skill_id_2'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0])) with self.assertRaisesRegexp( Exception, 'The skill id skill_id_1 already exists in subtopic with id 1' ): self.topic.add_uncategorized_skill_id('skill_id_1') self.topic.add_uncategorized_skill_id('skill_id_3') self.assertEqual(self.topic.uncategorized_skill_ids, ['skill_id_3'])
def setUp(self): """Completes the sign-up process for the various users.""" super(BaseTopicViewerControllerTests, self).setUp() self.signup(self.NEW_USER_EMAIL, self.NEW_USER_USERNAME) self.user_id = self.get_user_id_from_email(self.NEW_USER_EMAIL) 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.admin = user_services.UserActionsInfo(self.admin_id) self.topic_id = 'topic' self.story_id = 'story' self.topic_id_1 = 'topic1' self.skill_id_1 = skill_services.get_new_skill_id() self.skill_id_2 = skill_services.get_new_skill_id() self.story = story_domain.Story.create_default_story( self.story_id, 'story_title', self.topic_id_1) self.story.description = 'story_description' self.topic = topic_domain.Topic.create_default_topic( self.topic_id, 'public_topic_name', 'abbrev') self.topic.uncategorized_skill_ids.append(self.skill_id_1) self.topic.subtopics.append( topic_domain.Subtopic(1, 'subtopic_name', [self.skill_id_2])) self.topic.next_subtopic_id = 2 self.topic.thumbnail_filename = 'Image.png' self.topic.canonical_story_references.append( topic_domain.StoryReference.create_default_story_reference( self.story_id)) topic_services.save_new_topic(self.admin_id, self.topic) story_services.save_new_story(self.admin_id, self.story) self.topic = topic_domain.Topic.create_default_topic( self.topic_id_1, 'private_topic_name', 'abbrev') self.topic.thumbnail_filename = 'Image.png' topic_services.save_new_topic(self.admin_id, self.topic) topic_services.publish_topic(self.topic_id, self.admin_id) topic_services.publish_story(self.topic_id, self.story_id, self.admin_id) self.save_new_skill(self.skill_id_1, self.user_id, description='Skill Description 1') self.save_new_skill(self.skill_id_2, self.user_id, description='Skill Description 2') skill_services.create_user_skill_mastery(self.user_id, self.skill_id_1, 0.3) skill_services.create_user_skill_mastery(self.user_id, self.skill_id_2, 0.5)
def test_get_all_subtopics(self): self.topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0]) ] subtopics = self.topic.get_all_subtopics() self.assertEqual(subtopics, [{ 'skill_ids': ['skill_id_1'], 'id': 1, 'thumbnail_filename': 'image.svg', 'thumbnail_bg_color': '#FFFFFF', 'title': 'Title' }])
def setUp(self): super(TopicDomainUnitTests, self).setUp() self.signup('*****@*****.**', 'A') self.signup('*****@*****.**', 'B') self.topic = topic_domain.Topic.create_default_topic( self.topic_id, 'Name') self.topic.subtopics = [ topic_domain.Subtopic(1, 'Title', ['skill_id_1'])] self.topic.next_subtopic_id = 2 self.user_id_a = self.get_user_id_from_email('*****@*****.**') self.user_id_b = self.get_user_id_from_email('*****@*****.**') self.user_a = user_services.UserActionsInfo(self.user_id_a) self.user_b = user_services.UserActionsInfo(self.user_id_b)
def test_get_fails_when_skill_ids_dont_exist(self): topic = topic_domain.Topic.create_default_topic( 'topic_id_3', 'topic_without_skills', 'noskills', 'description') topic.thumbnail_filename = 'Topic.svg' topic.thumbnail_bg_color = ( constants.ALLOWED_THUMBNAIL_BG_COLORS['topic'][0]) topic.subtopics.append( topic_domain.Subtopic( 1, 'subtopic_name', ['non_existent_skill'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'subtopic-name-three')) topic.next_subtopic_id = 2 topic_services.save_new_topic(self.admin_id, topic) topic_services.publish_topic('topic_id_3', self.admin_id) self.get_json('%s/staging/%s?selected_subtopic_ids=[1]' % (feconf.PRACTICE_SESSION_DATA_URL_PREFIX, 'noskills'), expected_status_int=404)
def setUp(self): super(TopicDomainUnitTests, self).setUp() self.signup('*****@*****.**', 'A') self.signup('*****@*****.**', 'B') self.topic = topic_domain.Topic.create_default_topic( self.topic_id, 'Name', 'abbrev', 'description') self.topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0]) ] self.topic.next_subtopic_id = 2 self.user_id_a = self.get_user_id_from_email('*****@*****.**') self.user_id_b = self.get_user_id_from_email('*****@*****.**') self.user_a = user_services.UserActionsInfo(self.user_id_a) self.user_b = user_services.UserActionsInfo(self.user_id_b)
def test_get_fails_when_skill_ids_dont_exist(self): topic = topic_domain.Topic.create_default_topic( 'topic_id_3', 'topic_without_skills', 'abbrev') topic.thumbnail_filename = 'Topic.svg' topic.thumbnail_bg_color = ( constants.ALLOWED_THUMBNAIL_BG_COLORS['topic'][0]) topic.subtopics.append(topic_domain.Subtopic( 1, 'subtopic_name', ['non_existent_skill'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0])) topic.next_subtopic_id = 2 topic_services.save_new_topic(self.admin_id, topic) topic_services.publish_topic('topic_id_3', self.admin_id) with self.swap(constants, 'ENABLE_NEW_STRUCTURE_PLAYERS', True): self.get_json( '%s/%s?selected_subtopic_ids=1' % ( feconf.PRACTICE_SESSION_DATA_URL_PREFIX, 'topic_without_skills'), expected_status_int=404)
def _publish_topic(self, topic_id, topic_name): """Creates and publishes a topic. Args: topic_id: str. Topic ID. topic_name: str. Topic name. """ topic = topic_domain.Topic.create_default_topic( topic_id, topic_name, 'abbrev', 'description') topic.thumbnail_filename = 'thumbnail.svg' topic.thumbnail_bg_color = '#C6DCDA' topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_3'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-three')] topic.next_subtopic_id = 2 topic_services.save_new_topic(self.admin_id, topic) topic_services.publish_topic(topic_id, self.admin_id)
def _publish_valid_topic(self, topic, uncategorized_skill_ids): """Saves and publishes a valid topic with linked skills and subtopic. Args: topic: Topic. The topic to be saved and published. uncategorized_skill_ids: list(str). List of uncategorized skills IDs to add to the supplied topic. """ topic.thumbnail_filename = 'thumbnail.svg' topic.thumbnail_bg_color = '#C6DCDA' subtopic_id = 1 subtopic_skill_id = 'subtopic_skill_id' + topic.id topic.subtopics = [ topic_domain.Subtopic( subtopic_id, 'Title', [subtopic_skill_id], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic') ] topic.next_subtopic_id = 2 subtopic_page = ( subtopic_page_domain.SubtopicPage.create_default_subtopic_page( subtopic_id, topic.id)) subtopic_page_services.save_subtopic_page( self.owner_id, subtopic_page, 'Added subtopic', [ topic_domain.TopicChange({ 'cmd': topic_domain.CMD_ADD_SUBTOPIC, 'subtopic_id': 1, 'title': 'Sample' }) ]) topic_services.save_new_topic(self.owner_id, topic) topic_services.publish_topic(topic.id, self.admin_id) for skill_id in uncategorized_skill_ids: self.save_new_skill(skill_id, self.admin_id, description='skill_description') topic_services.add_uncategorized_skill(self.admin_id, topic.id, skill_id)
def setUp(self): super(TopicServicesUnitTests, self).setUp() self.TOPIC_ID = topic_services.get_new_topic_id() subtopic = topic_domain.Subtopic(self.subtopic_id, 'Title', [self.skill_id_2]) self.topic = self.save_new_topic(self.TOPIC_ID, self.user_id, 'Name', 'Description', [self.story_id_1, self.story_id_2], [self.story_id_3], [self.skill_id_1], [subtopic]) self.signup('*****@*****.**', 'A') self.signup('*****@*****.**', 'B') self.signup(self.ADMIN_EMAIL, username=self.ADMIN_USERNAME) self.user_id_a = self.get_user_id_from_email('*****@*****.**') self.user_id_b = self.get_user_id_from_email('*****@*****.**') self.user_id_admin = self.get_user_id_from_email(self.ADMIN_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.set_topic_managers([user_services.get_username(self.user_id_a)]) self.user_a = user_services.UserActionsInfo(self.user_id_a) self.user_b = user_services.UserActionsInfo(self.user_id_b) self.user_admin = user_services.UserActionsInfo(self.user_id_admin)
def setUp(self): super(OpportunityServicesIntegrationTest, self).setUp() self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.admin = user_services.UserActionsInfo(self.admin_id) self.TOPIC_ID = 'topic' self.STORY_ID = 'story' self.USER_ID = 'user' self.SKILL_ID = 'skill' self.QUESTION_ID = question_services.get_new_question_id() self.THREAD_ID = 'exploration.exp1.thread_1' # Since a valid exploration is created here, it has EndExploration # state as well, so the content in that has to be taken into account as # well when checking content_count in the tests. explorations = [ self.save_new_valid_exploration('%s' % i, self.owner_id, title='title %d' % i, category='category%d' % i, end_state_name='End State', correctness_feedback_enabled=True) for i in python_utils.RANGE(5) ] for exp in explorations: self.publish_exploration(self.owner_id, exp.id) topic = topic_domain.Topic.create_default_topic( self.TOPIC_ID, 'topic', 'abbrev', 'description') topic.thumbnail_filename = 'thumbnail.svg' topic.thumbnail_bg_color = '#C6DCDA' topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 'dummy-subtopic-url') ] topic.next_subtopic_id = 2 subtopic_page = ( subtopic_page_domain.SubtopicPage.create_default_subtopic_page( 1, self.TOPIC_ID)) subtopic_page_services.save_subtopic_page( self.owner_id, subtopic_page, 'Added subtopic', [ topic_domain.TopicChange({ 'cmd': topic_domain.CMD_ADD_SUBTOPIC, 'subtopic_id': 1, 'title': 'Sample' }) ]) topic_services.save_new_topic(self.owner_id, topic) topic_services.publish_topic(self.TOPIC_ID, self.admin_id) story = story_domain.Story.create_default_story( self.STORY_ID, 'A story', 'description', self.TOPIC_ID, 'story-one') story_services.save_new_story(self.owner_id, story) topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID, self.STORY_ID) topic_services.publish_story(self.TOPIC_ID, self.STORY_ID, self.admin_id)
def setUp(self): """Completes the sign-up process for the various users.""" super(BaseTopicViewerControllerTests, self).setUp() self.signup(self.NEW_USER_EMAIL, self.NEW_USER_USERNAME) self.user_id = self.get_user_id_from_email(self.NEW_USER_EMAIL) 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]) self.admin = user_services.get_user_actions_info(self.admin_id) self.topic_id = 'topic' self.story_id_1 = 'story_id_1' self.story_id_2 = 'story_id_2' self.topic_id_1 = 'topic1' self.topic_id_2 = 'topic2' self.skill_id_1 = skill_services.get_new_skill_id() self.skill_id_2 = skill_services.get_new_skill_id() self.story_1 = story_domain.Story.create_default_story( self.story_id_1, 'story_title', 'description', self.topic_id_1, 'story-frag-one') self.story_1.description = 'story_description' self.story_1.node_titles = [] self.story_2 = story_domain.Story.create_default_story( self.story_id_2, 'story_title', 'description', self.topic_id_2, 'story-frag-two') self.story_2.description = 'story_description' self.story_2.node_titles = [] self.topic = topic_domain.Topic.create_default_topic( self.topic_id, 'public_topic_name', 'public', 'description') self.topic.uncategorized_skill_ids.append(self.skill_id_1) self.topic.subtopics.append(topic_domain.Subtopic( 1, 'subtopic_name', [self.skill_id_2], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'subtopic-name')) self.topic.next_subtopic_id = 2 self.topic.thumbnail_filename = 'Image.svg' self.topic.thumbnail_bg_color = ( constants.ALLOWED_THUMBNAIL_BG_COLORS['topic'][0]) self.topic.canonical_story_references.append( topic_domain.StoryReference.create_default_story_reference( self.story_id_1)) self.topic.additional_story_references.append( topic_domain.StoryReference.create_default_story_reference( self.story_id_2)) self.topic.meta_tag_content = 'topic meta content' self.topic.page_title_fragment_for_web = 'topic page title' topic_services.save_new_topic(self.admin_id, self.topic) story_services.save_new_story(self.admin_id, self.story_1) story_services.save_new_story(self.admin_id, self.story_2) self.topic = topic_domain.Topic.create_default_topic( self.topic_id_1, 'private_topic_name', 'private_topic_name', 'description') self.topic.thumbnail_filename = 'Image.svg' self.topic.thumbnail_bg_color = ( constants.ALLOWED_THUMBNAIL_BG_COLORS['topic'][0]) self.topic.url_fragment = 'private' topic_services.save_new_topic(self.admin_id, self.topic) topic_services.publish_topic(self.topic_id, self.admin_id) topic_services.publish_story( self.topic_id, self.story_id_1, self.admin_id) topic_services.publish_story( self.topic_id, self.story_id_2, self.admin_id) self.save_new_skill( self.skill_id_1, self.user_id, description='Skill Description 1') self.save_new_skill( self.skill_id_2, self.user_id, description='Skill Description 2') skill_services.create_user_skill_mastery( self.user_id, self.skill_id_1, 0.3) skill_services.create_user_skill_mastery( self.user_id, self.skill_id_2, 0.5)
class LearnerGoalsHandlerTests(test_utils.GenericTestBase): OWNER_EMAIL = '*****@*****.**' OWNER_USERNAME = '******' TOPIC_ID_1 = 'Topic_id_1' TOPIC_NAME_1 = 'Topic name 1' TOPIC_ID_2 = 'Topic_id_2' TOPIC_NAME_2 = 'Topic name 2' TOPIC_ID_3 = 'Topic_id_3' TOPIC_NAME_3 = 'Topic name 3' TOPIC_ID_4 = 'Topic_id_4' TOPIC_NAME_4 = 'Topic name 4' subtopic_1 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-zero') subtopic_2 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-zero') subtopic_3 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-zero') subtopic_4 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-zero') def setUp(self): super(LearnerGoalsHandlerTests, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.signup(self.CURRICULUM_ADMIN_EMAIL, self.CURRICULUM_ADMIN_USERNAME) self.viewer_id = self.get_user_id_from_email(self.VIEWER_EMAIL) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.curriculum_admin_id = self.get_user_id_from_email( self.CURRICULUM_ADMIN_EMAIL) self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME]) # Save the topics. self.save_new_topic(self.TOPIC_ID_1, self.owner_id, name=self.TOPIC_NAME_1, url_fragment='topic-one', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_1], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_1, self.curriculum_admin_id) self.save_new_topic(self.TOPIC_ID_2, self.owner_id, name=self.TOPIC_NAME_2, url_fragment='topic-two', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_2], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_2, self.curriculum_admin_id) self.save_new_topic(self.TOPIC_ID_3, self.owner_id, name=self.TOPIC_NAME_3, url_fragment='topic-three', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_3], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_3, self.curriculum_admin_id) self.save_new_topic(self.TOPIC_ID_4, self.owner_id, name=self.TOPIC_NAME_4, url_fragment='topic-four', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_4], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_4, self.curriculum_admin_id) def test_add_topic_to_learner_goal(self): self.login(self.VIEWER_EMAIL) csrf_token = self.get_new_csrf_token() # Add one topic to the learner goal. self.post_json('%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, self.TOPIC_ID_1), {}, csrf_token=csrf_token) self.assertEqual( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1]) # Add another topic. self.post_json('%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, self.TOPIC_ID_2), {}, csrf_token=csrf_token) self.assertEqual( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2]) # If a topic belongs to the completed list, it should not be added. learner_progress_services.mark_topic_as_learnt(self.viewer_id, self.TOPIC_ID_3) response = self.post_json( '%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, self.TOPIC_ID_3), {}, csrf_token=csrf_token) self.assertEqual(response['belongs_to_learnt_list'], True) self.assertEqual( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2]) # Fail to add one topic to the learner goal. response = self.post_json( '%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, 'InvalidActivityType', self.TOPIC_ID_1), {}, csrf_token=csrf_token, expected_status_int=400) self.assertEqual(response['error'], 'Invalid activityType: InvalidActivityType') # Now we begin testing of not exceeding the limit of activities in the # learner goals. # Add feconf.MAX_CURRENT_GOALS_COUNT - 2 activities to reach # the maximum limit. for topic_id in python_utils.RANGE(2, feconf.MAX_CURRENT_GOALS_COUNT + 1): self.post_json('%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, 'topic_id_%s' % topic_id), {}, csrf_token=csrf_token) # Now if we try and add a topic we should get a message saying we # are exceeding the limit. response = self.post_json( '%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, 'topic_id_%s' % python_utils.UNICODE(feconf.MAX_CURRENT_GOALS_COUNT + 3)), {}, csrf_token=csrf_token) self.assertEqual(response['goals_limit_exceeded'], True) self.logout() def test_remove_topic_from_learner_goals(self): self.login(self.VIEWER_EMAIL) csrf_token = self.get_new_csrf_token() # Add topic to the learner goals. learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_1) learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_2) self.assertEqual( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2]) # Remove an topic. self.delete_json( '%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, self.TOPIC_ID_1)) self.assertEqual( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_2]) # Remove the second topic. self.delete_json( '%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, self.TOPIC_ID_2)) self.assertEqual( learner_goals_services.get_all_topic_ids_to_learn(self.viewer_id), []) # Add one topic to the learner goal. self.post_json('%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, constants.ACTIVITY_TYPE_LEARN_TOPIC, self.TOPIC_ID_1), {}, csrf_token=csrf_token) # Fail to delete one topic from learner goals. response = self.delete_json( '%s/%s/%s' % (feconf.LEARNER_GOALS_DATA_URL, 'InvalidActivityType', self.TOPIC_ID_1), expected_status_int=400) self.assertEqual(response['error'], 'Invalid activityType: InvalidActivityType') self.logout()
def setUp(self): super(ExplorationOpportunitySummaryModelRegenerationJobTest, self).setUp() self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.topic_id_1 = 'topic1' self.topic_id_2 = 'topic2' story_id_1 = 'story1' story_id_2 = 'story2' explorations = [ self.save_new_valid_exploration('%s' % i, self.owner_id, title='title %d' % i, end_state_name='End State', correctness_feedback_enabled=True) for i in python_utils.RANGE(2) ] for exp in explorations: self.publish_exploration(self.owner_id, exp.id) topic_1 = topic_domain.Topic.create_default_topic( self.topic_id_1, 'topic', 'abbrev-one', 'description') topic_1.thumbnail_filename = 'thumbnail.svg' topic_1.thumbnail_bg_color = '#C6DCDA' topic_1.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 'dummy-subtopic-three') ] topic_1.next_subtopic_id = 2 subtopic_page = ( subtopic_page_domain.SubtopicPage.create_default_subtopic_page( 1, self.topic_id_1)) subtopic_page_services.save_subtopic_page( self.owner_id, subtopic_page, 'Added subtopic', [ topic_domain.TopicChange({ 'cmd': topic_domain.CMD_ADD_SUBTOPIC, 'subtopic_id': 1, 'title': 'Sample' }) ]) topic_services.save_new_topic(self.owner_id, topic_1) topic_services.publish_topic(self.topic_id_1, self.admin_id) topic_2 = topic_domain.Topic.create_default_topic( self.topic_id_2, 'topic2', 'abbrev-two', 'description') topic_2.thumbnail_filename = 'thumbnail.svg' topic_2.thumbnail_bg_color = '#C6DCDA' topic_2.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_2'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 'dummy-subtopic-three') ] subtopic_page = ( subtopic_page_domain.SubtopicPage.create_default_subtopic_page( 1, self.topic_id_2)) subtopic_page_services.save_subtopic_page( self.owner_id, subtopic_page, 'Added subtopic', [ topic_domain.TopicChange({ 'cmd': topic_domain.CMD_ADD_SUBTOPIC, 'subtopic_id': 1, 'title': 'Sample' }) ]) topic_2.next_subtopic_id = 2 topic_services.save_new_topic(self.owner_id, topic_2) topic_services.publish_topic(self.topic_id_2, self.admin_id) story_1 = story_domain.Story.create_default_story( story_id_1, 'A story', 'description', self.topic_id_1, 'story-one') story_2 = story_domain.Story.create_default_story( story_id_2, 'A story', 'description', self.topic_id_2, 'story-two') story_services.save_new_story(self.owner_id, story_1) story_services.save_new_story(self.owner_id, story_2) topic_services.add_canonical_story(self.owner_id, self.topic_id_1, story_id_1) topic_services.publish_story(self.topic_id_1, story_id_1, self.admin_id) topic_services.add_canonical_story(self.owner_id, self.topic_id_2, story_id_2) topic_services.publish_story(self.topic_id_2, story_id_2, self.admin_id) story_services.update_story(self.owner_id, story_id_1, [ story_domain.StoryChange({ 'cmd': 'add_story_node', 'node_id': 'node_1', 'title': 'Node1', }), story_domain.StoryChange({ 'cmd': 'update_story_node_property', 'property_name': 'exploration_id', 'node_id': 'node_1', 'old_value': None, 'new_value': '0' }) ], 'Changes.') story_services.update_story(self.owner_id, story_id_2, [ story_domain.StoryChange({ 'cmd': 'add_story_node', 'node_id': 'node_1', 'title': 'Node1', }), story_domain.StoryChange({ 'cmd': 'update_story_node_property', 'property_name': 'exploration_id', 'node_id': 'node_1', 'old_value': None, 'new_value': '1' }) ], 'Changes.')
class LearnerDashboardHandlerTests(test_utils.GenericTestBase): OWNER_EMAIL = '*****@*****.**' OWNER_USERNAME = '******' EXP_ID_1 = 'EXP_ID_1' EXP_TITLE_1 = 'Exploration title 1' EXP_ID_2 = 'EXP_ID_2' EXP_TITLE_2 = 'Exploration title 2' EXP_ID_3 = 'EXP_ID_3' EXP_TITLE_3 = 'Exploration title 3' COL_ID_1 = 'COL_ID_1' COL_TITLE_1 = 'Collection title 1' COL_ID_2 = 'COL_ID_2' COL_TITLE_2 = 'Collection title 2' COL_ID_3 = 'COL_ID_3' COL_TITLE_3 = 'Collection title 3' STORY_ID_1 = 'STORY_1' STORY_TITLE_1 = 'Story title 1' STORY_ID_2 = 'STORY_2' STORY_TITLE_2 = 'Story title 2' STORY_ID_3 = 'STORY_3' STORY_TITLE_3 = 'Story title 3' TOPIC_ID_1 = 'TOPIC_1' TOPIC_NAME_1 = 'Topic title 1' TOPIC_ID_2 = 'TOPIC_2' TOPIC_NAME_2 = 'Topic title 2' TOPIC_ID_3 = 'TOPIC_3' TOPIC_NAME_3 = 'Topic title 3' subtopic_0 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 'dummy-subtopic-zero') subtopic_1 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 'dummy-subtopic-zero') def setUp(self): super(LearnerDashboardHandlerTests, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.set_admins([self.ADMIN_USERNAME]) self.viewer_id = self.get_user_id_from_email(self.VIEWER_EMAIL) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) def test_can_see_completed_explorations(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['completed_explorations_list']), 0) self.save_new_default_exploration(self.EXP_ID_1, self.owner_id, title=self.EXP_TITLE_1) self.publish_exploration(self.owner_id, self.EXP_ID_1) learner_progress_services.mark_exploration_as_completed( self.viewer_id, self.EXP_ID_1) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['completed_explorations_list']), 1) self.assertEqual(response['completed_explorations_list'][0]['id'], self.EXP_ID_1) self.logout() def test_can_see_completed_collections(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['completed_collections_list']), 0) self.save_new_default_collection(self.COL_ID_1, self.owner_id, title=self.COL_TITLE_1) self.publish_collection(self.owner_id, self.COL_ID_1) learner_progress_services.mark_collection_as_completed( self.viewer_id, self.COL_ID_1) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['completed_collections_list']), 1) self.assertEqual(response['completed_collections_list'][0]['id'], self.COL_ID_1) self.logout() def test_can_see_completed_stories(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['completed_stories_list']), 0) self.save_new_topic(self.TOPIC_ID_1, self.owner_id, name=self.TOPIC_NAME_1, url_fragment='topic-one', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_0], next_subtopic_id=1) self.save_new_story(self.STORY_ID_1, self.owner_id, self.TOPIC_ID_1) topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_1, self.STORY_ID_1) topic_services.publish_story(self.TOPIC_ID_1, self.STORY_ID_1, self.admin_id) topic_services.publish_topic(self.TOPIC_ID_1, self.admin_id) learner_progress_services.mark_story_as_completed( self.viewer_id, self.STORY_ID_1) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['completed_stories_list']), 1) self.assertEqual(response['completed_stories_list'][0]['id'], self.STORY_ID_1) self.logout() def test_can_see_learnt_topics(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['learnt_topics_list']), 0) self.save_new_topic(self.TOPIC_ID_1, self.owner_id, name=self.TOPIC_NAME_1, url_fragment='topic-one', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_0], next_subtopic_id=1) self.save_new_story(self.STORY_ID_1, self.owner_id, self.TOPIC_ID_1) topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_1, self.STORY_ID_1) topic_services.publish_story(self.TOPIC_ID_1, self.STORY_ID_1, self.admin_id) topic_services.publish_topic(self.TOPIC_ID_1, self.admin_id) learner_progress_services.mark_story_as_completed( self.viewer_id, self.STORY_ID_1) learner_progress_services.mark_topic_as_learnt(self.viewer_id, self.TOPIC_ID_1) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['learnt_topics_list']), 1) self.assertEqual(response['learnt_topics_list'][0]['id'], self.TOPIC_ID_1) self.logout() def test_can_see_incomplete_explorations(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['incomplete_explorations_list']), 0) self.save_new_default_exploration(self.EXP_ID_1, self.owner_id, title=self.EXP_TITLE_1) self.publish_exploration(self.owner_id, self.EXP_ID_1) state_name = 'state_name' version = 1 learner_progress_services.mark_exploration_as_incomplete( self.viewer_id, self.EXP_ID_1, state_name, version) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['incomplete_explorations_list']), 1) self.assertEqual(response['incomplete_explorations_list'][0]['id'], self.EXP_ID_1) self.logout() def test_can_see_incomplete_collections(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['incomplete_collections_list']), 0) self.save_new_default_collection(self.COL_ID_1, self.owner_id, title=self.COL_TITLE_1) self.publish_collection(self.owner_id, self.COL_ID_1) learner_progress_services.mark_collection_as_incomplete( self.viewer_id, self.COL_ID_1) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['incomplete_collections_list']), 1) self.assertEqual(response['incomplete_collections_list'][0]['id'], self.COL_ID_1) self.logout() def test_can_see_partially_learnt_topics(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['partially_learnt_topics_list']), 0) self.save_new_topic(self.TOPIC_ID_1, self.owner_id, name=self.TOPIC_NAME_1, url_fragment='topic-one', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_0], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_1, self.admin_id) learner_progress_services.record_topic_started(self.viewer_id, self.TOPIC_ID_1) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['partially_learnt_topics_list']), 1) self.assertEqual(response['partially_learnt_topics_list'][0]['id'], self.TOPIC_ID_1) self.logout() def test_can_see_topics_to_learn(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['topics_to_learn_list']), 0) self.save_new_topic(self.TOPIC_ID_1, self.owner_id, name=self.TOPIC_NAME_1, url_fragment='topic-one', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_0], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_1, self.admin_id) self.save_new_story(self.STORY_ID_2, self.owner_id, self.TOPIC_ID_1) topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_1, self.STORY_ID_2) topic_services.publish_story(self.TOPIC_ID_1, self.STORY_ID_2, self.admin_id) learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_1) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['topics_to_learn_list']), 1) self.assertEqual(response['topics_to_learn_list'][0]['id'], self.TOPIC_ID_1) self.logout() def test_can_see_all_topics(self): self.login(self.ADMIN_EMAIL, is_super_admin=True) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['all_topics_list']), 0) self.save_new_topic(self.TOPIC_ID_1, self.owner_id, name=self.TOPIC_NAME_1, url_fragment='topic-one', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_0], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_1, self.admin_id) self.save_new_story(self.STORY_ID_2, self.owner_id, self.TOPIC_ID_1) topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_1, self.STORY_ID_2) topic_services.publish_story(self.TOPIC_ID_1, self.STORY_ID_2, self.admin_id) csrf_token = self.get_new_csrf_token() new_config_value = [{ 'name': 'math', 'url_fragment': 'math', 'topic_ids': [self.TOPIC_ID_1], 'course_details': '', 'topic_list_intro': '' }] payload = { 'action': 'save_config_properties', 'new_config_property_values': { config_domain.CLASSROOM_PAGES_DATA.name: (new_config_value), } } self.post_json('/adminhandler', payload, csrf_token=csrf_token) self.logout() self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['all_topics_list']), 1) self.assertEqual(response['all_topics_list'][0]['id'], self.TOPIC_ID_1) self.logout() def test_can_see_untracked_topics(self): self.login(self.ADMIN_EMAIL, is_super_admin=True) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['untracked_topics_list']), 0) self.save_new_topic(self.TOPIC_ID_1, self.owner_id, name=self.TOPIC_NAME_1, url_fragment='topic-one', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_0], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_1, self.admin_id) self.save_new_story(self.STORY_ID_2, self.owner_id, self.TOPIC_ID_1) topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_1, self.STORY_ID_2) topic_services.publish_story(self.TOPIC_ID_1, self.STORY_ID_2, self.admin_id) csrf_token = self.get_new_csrf_token() new_config_value = [{ 'name': 'math', 'url_fragment': 'math', 'topic_ids': [self.TOPIC_ID_1], 'course_details': '', 'topic_list_intro': '' }] payload = { 'action': 'save_config_properties', 'new_config_property_values': { config_domain.CLASSROOM_PAGES_DATA.name: (new_config_value), } } self.post_json('/adminhandler', payload, csrf_token=csrf_token) self.logout() self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['untracked_topics_list']), 1) self.assertEqual(response['untracked_topics_list'][0]['id'], self.TOPIC_ID_1) self.logout() def test_can_see_exploration_playlist(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['exploration_playlist']), 0) self.save_new_default_exploration(self.EXP_ID_1, self.owner_id, title=self.EXP_TITLE_1) self.publish_exploration(self.owner_id, self.EXP_ID_1) learner_progress_services.add_exp_to_learner_playlist( self.viewer_id, self.EXP_ID_1) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['exploration_playlist']), 1) self.assertEqual(response['exploration_playlist'][0]['id'], self.EXP_ID_1) self.logout() def test_can_see_collection_playlist(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['collection_playlist']), 0) self.save_new_default_collection(self.COL_ID_1, self.owner_id, title=self.COL_TITLE_1) self.publish_collection(self.owner_id, self.COL_ID_1) learner_progress_services.add_collection_to_learner_playlist( self.viewer_id, self.COL_ID_1) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['collection_playlist']), 1) self.assertEqual(response['collection_playlist'][0]['id'], self.COL_ID_1) self.logout() def test_can_see_subscription(self): self.login(self.VIEWER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['subscription_list']), 0) subscription_services.subscribe_to_creator(self.viewer_id, self.owner_id) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) self.assertEqual(len(response['subscription_list']), 1) self.assertEqual(response['subscription_list'][0]['creator_username'], self.OWNER_USERNAME) self.logout() def test_get_learner_dashboard_ids(self): self.login(self.VIEWER_EMAIL) self.save_new_default_exploration(self.EXP_ID_1, self.owner_id, title=self.EXP_TITLE_1) self.publish_exploration(self.owner_id, self.EXP_ID_1) self.save_new_default_exploration(self.EXP_ID_2, self.owner_id, title=self.EXP_TITLE_2) self.publish_exploration(self.owner_id, self.EXP_ID_2) self.save_new_default_exploration(self.EXP_ID_3, self.owner_id, title=self.EXP_TITLE_3) self.publish_exploration(self.owner_id, self.EXP_ID_3) self.save_new_default_collection(self.COL_ID_1, self.owner_id, title=self.COL_TITLE_1) self.publish_collection(self.owner_id, self.COL_ID_1) self.save_new_default_collection(self.COL_ID_2, self.owner_id, title=self.COL_TITLE_2) self.publish_collection(self.owner_id, self.COL_ID_2) self.save_new_default_collection(self.COL_ID_3, self.owner_id, title=self.COL_TITLE_3) self.publish_collection(self.owner_id, self.COL_ID_3) self.save_new_topic(self.TOPIC_ID_1, self.owner_id, name=self.TOPIC_NAME_1, url_fragment='topic-one', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_0], next_subtopic_id=1) self.save_new_story(self.STORY_ID_1, self.owner_id, self.TOPIC_ID_1) topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_1, self.STORY_ID_1) topic_services.publish_story(self.TOPIC_ID_1, self.STORY_ID_1, self.admin_id) topic_services.publish_topic(self.TOPIC_ID_1, self.admin_id) self.save_new_topic(self.TOPIC_ID_2, self.owner_id, name=self.TOPIC_NAME_2, url_fragment='topic-two', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_1], next_subtopic_id=1) self.save_new_story(self.STORY_ID_2, self.owner_id, self.TOPIC_ID_2) topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_2, self.STORY_ID_2) topic_services.publish_story(self.TOPIC_ID_2, self.STORY_ID_2, self.admin_id) topic_services.publish_topic(self.TOPIC_ID_2, self.admin_id) self.save_new_topic(self.TOPIC_ID_3, self.owner_id, name=self.TOPIC_NAME_3, url_fragment='topic-three', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_1], next_subtopic_id=1) self.save_new_story(self.STORY_ID_3, self.owner_id, self.TOPIC_ID_3) topic_services.add_canonical_story(self.owner_id, self.TOPIC_ID_3, self.STORY_ID_3) topic_services.publish_story(self.TOPIC_ID_3, self.STORY_ID_3, self.admin_id) topic_services.publish_topic(self.TOPIC_ID_3, self.admin_id) state_name = 'state_name' version = 1 learner_progress_services.mark_exploration_as_completed( self.viewer_id, self.EXP_ID_1) learner_progress_services.mark_exploration_as_incomplete( self.viewer_id, self.EXP_ID_2, state_name, version) learner_progress_services.add_exp_to_learner_playlist( self.viewer_id, self.EXP_ID_3) learner_progress_services.mark_collection_as_completed( self.viewer_id, self.COL_ID_1) learner_progress_services.mark_collection_as_incomplete( self.viewer_id, self.COL_ID_2) learner_progress_services.add_collection_to_learner_playlist( self.viewer_id, self.COL_ID_3) learner_progress_services.mark_story_as_completed( self.viewer_id, self.STORY_ID_1) learner_progress_services.mark_topic_as_learnt(self.viewer_id, self.TOPIC_ID_1) learner_progress_services.record_topic_started(self.viewer_id, self.TOPIC_ID_2) learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_3) response = self.get_json(feconf.LEARNER_DASHBOARD_IDS_DATA_URL) learner_dashboard_activity_ids = ( response['learner_dashboard_activity_ids']) self.assertEqual( learner_dashboard_activity_ids['completed_exploration_ids'], [self.EXP_ID_1]) self.assertEqual( learner_dashboard_activity_ids['incomplete_exploration_ids'], [self.EXP_ID_2]) self.assertEqual( learner_dashboard_activity_ids['exploration_playlist_ids'], [self.EXP_ID_3]) self.assertEqual( learner_dashboard_activity_ids['completed_collection_ids'], [self.COL_ID_1]) self.assertEqual( learner_dashboard_activity_ids['incomplete_collection_ids'], [self.COL_ID_2]) self.assertEqual( learner_dashboard_activity_ids['collection_playlist_ids'], [self.COL_ID_3]) self.assertEqual(learner_dashboard_activity_ids['completed_story_ids'], [self.STORY_ID_1]) self.assertEqual(learner_dashboard_activity_ids['learnt_topic_ids'], [self.TOPIC_ID_1]) self.assertEqual( learner_dashboard_activity_ids['partially_learnt_topic_ids'], [self.TOPIC_ID_2]) self.assertEqual(learner_dashboard_activity_ids['topic_ids_to_learn'], [self.TOPIC_ID_3]) def test_get_threads_after_updating_thread_summaries(self): self.login(self.OWNER_EMAIL) response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) thread_summaries = response['thread_summaries'] self.assertEqual(thread_summaries, []) self.save_new_default_exploration(self.EXP_ID_1, self.owner_id, title=self.EXP_TITLE_1) feedback_services.create_thread('exploration', self.EXP_ID_1, self.owner_id, 'a subject', 'some text') response = self.get_json(feconf.LEARNER_DASHBOARD_DATA_URL) thread_summaries = response['thread_summaries'] thread_id = thread_summaries[0]['thread_id'] thread = feedback_services.get_thread(thread_id) self.assertEqual(len(thread_summaries), 1) self.assertEqual(thread_summaries[0]['total_message_count'], 1) self.assertEqual(thread_summaries[0]['exploration_title'], self.EXP_TITLE_1) self.assertEqual(thread_summaries[0]['exploration_id'], self.EXP_ID_1) self.assertEqual(thread_summaries[0]['last_message_text'], 'some text') self.assertEqual(thread_summaries[0]['original_author_id'], self.owner_id) self.assertEqual(thread.subject, 'a subject') self.assertEqual(thread.entity_type, 'exploration') self.logout() def test_learner_dashboard_page(self): self.login(self.OWNER_EMAIL) response = self.get_html_response(feconf.LEARNER_DASHBOARD_URL) self.assertIn('{"title": "Learner Dashboard | Oppia"})', response.body) self.logout()
def setUp(self): super(VoiceoverApplicationServicesUnitTests, self).setUp() self.signup(self.CURRICULUM_ADMIN_EMAIL, self.CURRICULUM_ADMIN_USERNAME) self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.APPLICANT_EMAIL, self.APPLICANT_USERNAME) self.admin_id = self.get_user_id_from_email(self.CURRICULUM_ADMIN_EMAIL) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.applicant_id = self.get_user_id_from_email(self.APPLICANT_EMAIL) self.applicant = user_services.get_user_actions_info(self.applicant_id) self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME]) self.admin = user_services.get_user_actions_info(self.admin_id) self.TOPIC_ID = 'topic' self.STORY_ID = 'story' self.USER_ID = 'user' self.SKILL_ID = 'skill' self.QUESTION_ID = question_services.get_new_question_id() explorations = [self.save_new_valid_exploration( '%s' % i, self.owner_id, title='title %d' % i, category='category%d' % i, end_state_name='End State', correctness_feedback_enabled=True ) for i in range(2)] for exp in explorations: self.publish_exploration(self.owner_id, exp.id) topic = topic_domain.Topic.create_default_topic( self.TOPIC_ID, 'topic', 'abbrev', 'description') topic.thumbnail_filename = 'thumbnail.svg' topic.thumbnail_bg_color = '#C6DCDA' topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-three')] topic.next_subtopic_id = 2 topic_services.save_new_topic(self.owner_id, topic) topic_services.publish_topic(self.TOPIC_ID, self.admin_id) story = story_domain.Story.create_default_story( self.STORY_ID, 'A story', 'Description', self.TOPIC_ID, 'a-story') story_services.save_new_story(self.owner_id, story) topic_services.add_canonical_story( self.owner_id, self.TOPIC_ID, self.STORY_ID) topic_services.publish_story( self.TOPIC_ID, self.STORY_ID, self.admin_id) story_services.update_story( self.owner_id, self.STORY_ID, [story_domain.StoryChange({ 'cmd': 'add_story_node', 'node_id': 'node_1', 'title': 'Node1', }), story_domain.StoryChange({ 'cmd': 'update_story_node_property', 'property_name': 'exploration_id', 'node_id': 'node_1', 'old_value': None, 'new_value': '0' })], 'Changes.') self.add_user_role( self.CURRICULUM_ADMIN_USERNAME, feconf.ROLE_ID_VOICEOVER_ADMIN)
def setUp(self): super(TranslatableTextHandlerTest, self).setUp() self.signup(self.CURRICULUM_ADMIN_EMAIL, self.CURRICULUM_ADMIN_USERNAME) self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.admin_id = self.get_user_id_from_email(self.CURRICULUM_ADMIN_EMAIL) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME]) explorations = [self.save_new_valid_exploration( '%s' % i, self.owner_id, title='title %d' % i, category='category%d' % i, end_state_name='End State', correctness_feedback_enabled=True ) for i in python_utils.RANGE(2)] for exp in explorations: self.publish_exploration(self.owner_id, exp.id) topic = topic_domain.Topic.create_default_topic( '0', 'topic', 'abbrev', 'description') topic.thumbnail_filename = 'thumbnail.svg' topic.thumbnail_bg_color = '#C6DCDA' topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-three')] topic.next_subtopic_id = 2 topic_services.save_new_topic(self.owner_id, topic) topic_services.publish_topic(topic.id, self.admin_id) stories = [story_domain.Story.create_default_story( '%s' % i, 'title %d' % i, 'description %d' % i, '0', 'title-%s' % chr(97 + i) ) for i in python_utils.RANGE(2)] for index, story in enumerate(stories): story.language_code = 'en' story_services.save_new_story(self.owner_id, story) topic_services.add_canonical_story( self.owner_id, topic.id, story.id) topic_services.publish_story(topic.id, story.id, self.admin_id) story_services.update_story( self.owner_id, story.id, [story_domain.StoryChange({ 'cmd': 'add_story_node', 'node_id': 'node_1', 'title': 'Node1', }), story_domain.StoryChange({ 'cmd': 'update_story_node_property', 'property_name': 'exploration_id', 'node_id': 'node_1', 'old_value': None, 'new_value': explorations[index].id })], 'Changes.')
def setUp(self): super(ContributionOpportunitiesHandlerTest, self).setUp() self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.set_admins([self.ADMIN_USERNAME]) explorations = [ self.save_new_valid_exploration('%s' % i, self.owner_id, title='title %d' % i, category='category%d' % i, end_state_name='End State', correctness_feedback_enabled=True) for i in python_utils.RANGE(2) ] for exp in explorations: self.publish_exploration(self.owner_id, exp.id) topic = topic_domain.Topic.create_default_topic( '0', 'topic', 'abbrev', 'description') topic.thumbnail_filename = 'thumbnail.svg' topic.thumbnail_bg_color = '#C6DCDA' topic.subtopics = [ topic_domain.Subtopic( 1, 'Title', ['skill_id_3'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 'dummy-subtopic-three') ] topic.next_subtopic_id = 2 topic_services.save_new_topic(self.owner_id, topic) topic_services.publish_topic('0', self.admin_id) self.skill_id_0 = 'skill_id_0' self.skill_id_1 = 'skill_id_1' self.skill_ids = [self.skill_id_0, self.skill_id_1] for skill_id in self.skill_ids: self.save_new_skill(skill_id, self.admin_id, description='skill_description') topic_services.add_uncategorized_skill(self.admin_id, '0', skill_id) self.expected_skill_opportunity_dict_0 = { 'id': self.skill_id_0, 'skill_description': 'skill_description', 'question_count': 0, 'topic_name': 'topic' } self.expected_skill_opportunity_dict_1 = { 'id': self.skill_id_1, 'skill_description': 'skill_description', 'question_count': 0, 'topic_name': 'topic' } stories = [ story_domain.Story.create_default_story('%s' % i, 'title %d' % i, 'description %d' % i, '0', 'title-%s' % chr(97 + i)) for i in python_utils.RANGE(2) ] for index, story in enumerate(stories): story.language_code = 'en' story_services.save_new_story(self.owner_id, story) topic_services.add_canonical_story(self.owner_id, topic.id, story.id) topic_services.publish_story(topic.id, story.id, self.admin_id) story_services.update_story(self.owner_id, story.id, [ story_domain.StoryChange({ 'cmd': 'add_story_node', 'node_id': 'node_1', 'title': 'Node1', }), story_domain.StoryChange({ 'cmd': 'update_story_node_property', 'property_name': 'exploration_id', 'node_id': 'node_1', 'old_value': None, 'new_value': explorations[index].id }) ], 'Changes.') # The content_count is 4 for the expected dicts below since a valid # exploration with EndExploration is created above, so the content in # the last state is also included in the count. This content includes: # 2 content, 1 TextInput interaction customization argument # (placeholder), and 1 outcome. self.expected_opportunity_dict_1 = { 'id': '0', 'topic_name': 'topic', 'story_title': 'title 0', 'chapter_title': 'Node1', 'content_count': 2, 'translation_counts': {} } self.expected_opportunity_dict_2 = { 'id': '1', 'topic_name': 'topic', 'story_title': 'title 1', 'chapter_title': 'Node1', 'content_count': 2, 'translation_counts': {} } config_services.set_property('admin', 'contributor_dashboard_is_enabled', True)
class LearnerGoalsTests(test_utils.GenericTestBase): """Test the services related to learner goals services.""" OWNER_EMAIL = '*****@*****.**' OWNER_USERNAME = '******' TOPIC_ID_1 = 'Topic_id_1' TOPIC_NAME_1 = 'Topic name 1' TOPIC_ID_2 = 'Topic_id_2' TOPIC_NAME_2 = 'Topic name 2' TOPIC_ID_3 = 'Topic_id_3' TOPIC_NAME_3 = 'Topic name 3' TOPIC_ID_4 = 'Topic_id_4' TOPIC_NAME_4 = 'Topic name 4' subtopic_1 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-zero') subtopic_2 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-zero') subtopic_3 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-zero') subtopic_4 = topic_domain.Subtopic( 0, 'Title 1', ['skill_id_1'], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], 21131, 'dummy-subtopic-zero') def setUp(self): super(LearnerGoalsTests, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.signup(self.CURRICULUM_ADMIN_EMAIL, self.CURRICULUM_ADMIN_USERNAME) self.viewer_id = self.get_user_id_from_email(self.VIEWER_EMAIL) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.curriculum_admin_id = self.get_user_id_from_email( self.CURRICULUM_ADMIN_EMAIL) self.set_curriculum_admins([self.CURRICULUM_ADMIN_USERNAME]) # Save the topics. self.save_new_topic(self.TOPIC_ID_1, self.owner_id, name=self.TOPIC_NAME_1, url_fragment='topic-one', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_1], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_1, self.curriculum_admin_id) self.save_new_topic(self.TOPIC_ID_2, self.owner_id, name=self.TOPIC_NAME_2, url_fragment='topic-two', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_2], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_2, self.curriculum_admin_id) self.save_new_topic(self.TOPIC_ID_3, self.owner_id, name=self.TOPIC_NAME_3, url_fragment='topic-three', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_3], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_3, self.curriculum_admin_id) self.save_new_topic(self.TOPIC_ID_4, self.owner_id, name=self.TOPIC_NAME_4, url_fragment='topic-four', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[self.subtopic_4], next_subtopic_id=1) topic_services.publish_topic(self.TOPIC_ID_4, self.curriculum_admin_id) def _get_all_topic_ids_to_learn(self, user_id): """Returns the list of all the topic ids to learn corresponding to the given user id. """ learner_goals_model = user_models.LearnerGoalsModel.get(user_id, strict=False) return (learner_goals_model.topic_ids_to_learn if learner_goals_model else []) def test_single_topic_is_added_correctly_to_learn(self): # Test adding a single topic_id to learn. self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), []) learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_1) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1]) def test_multiple_topics_are_added_correctly_to_learn(self): # Test adding two topics to the learn. self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), []) learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_1) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1]) learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_2) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2]) def test_adding_exisiting_topic_is_not_added_again(self): # Test adding the topic_id if it is already in # learner_goals.topic_id. learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_1) learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_2) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2]) with self.assertRaisesRegexp( Exception, 'The topic id Topic_id_1 is already present in the learner goals' ): learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_1) def test_completed_topic_is_not_added_to_learner_goals(self): learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, self.TOPIC_ID_1) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1]) learner_progress_services.mark_topic_as_learnt(self.viewer_id, self.TOPIC_ID_2) # Test that the topic added to the in the learnt list doesn't get # added to the learner goals. self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1]) def test_number_of_topics_cannot_exceed_max(self): # Add MAX_CURRENT_GOALS_COUNT topics. topic_ids = [ 'SAMPLE_TOPIC_ID_%s' % index for index in (python_utils.RANGE(0, MAX_CURRENT_GOALS_COUNT)) ] for topic_id in topic_ids: learner_progress_services.validate_and_add_topic_to_learn_goal( self.viewer_id, topic_id) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), topic_ids) # Now if we try to add another topic at the end of the list, # it shouldn't be added as the list length would exceed # MAX_CURRENT_GOALS_COUNT. learner_goals_services.mark_topic_to_learn(self.viewer_id, 'SAMPLE_TOPIC_ID_MAX') self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), topic_ids) def test_remove_topic_from_learner_goals(self): self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), []) # Add topic to learner goals. learner_goals_services.mark_topic_to_learn(self.viewer_id, self.TOPIC_ID_1) learner_goals_services.mark_topic_to_learn(self.viewer_id, self.TOPIC_ID_2) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2]) # Removing a topic. learner_goals_services.remove_topics_from_learn_goal( self.viewer_id, [self.TOPIC_ID_1]) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_2]) # Removing the same topic raises error. with self.assertRaisesRegexp( Exception, 'The topic id Topic_id_1 is not present in LearnerGoalsModel'): learner_goals_services.remove_topics_from_learn_goal( self.viewer_id, [self.TOPIC_ID_1]) # Removing the second topic. learner_goals_services.remove_topics_from_learn_goal( self.viewer_id, [self.TOPIC_ID_2]) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), []) def test_get_all_topic_ids_in_learn(self): self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), []) # Add an topic to the learner goals. learner_goals_services.mark_topic_to_learn(self.viewer_id, self.TOPIC_ID_1) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1]) # Add another topic. learner_goals_services.mark_topic_to_learn(self.viewer_id, self.TOPIC_ID_2) self.assertEqual(self._get_all_topic_ids_to_learn(self.viewer_id), [self.TOPIC_ID_1, self.TOPIC_ID_2])