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>') ] 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 setUp(self): super(StoryFetchersUnitTests, self).setUp() self.STORY_ID = story_services.get_new_story_id() self.TOPIC_ID = topic_services.get_new_topic_id() self.save_new_topic(self.TOPIC_ID, self.USER_ID, name='Topic', description='A new topic', canonical_story_ids=[], additional_story_ids=[], uncategorized_skill_ids=[], subtopics=[], next_subtopic_id=0) self.save_new_story(self.STORY_ID, self.USER_ID, 'Title', 'Description', 'Notes', self.TOPIC_ID) topic_services.add_canonical_story(self.USER_ID, self.TOPIC_ID, self.STORY_ID) changelist = [ story_domain.StoryChange({ 'cmd': story_domain.CMD_ADD_STORY_NODE, 'node_id': self.NODE_ID_1, 'title': 'Title 1' }) ] story_services.update_story(self.USER_ID, self.STORY_ID, changelist, 'Added node.') self.story = story_fetchers.get_story_by_id(self.STORY_ID) 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 accept_voiceover_application(voiceover_application_id, reviewer_id): """Accept the voiceover application of given voiceover application id. Args: voiceover_application_id: str. The id of the voiceover application which need to be accepted. reviewer_id: str. The user ID of the reviewer. """ voiceover_application = get_voiceover_application_by_id( voiceover_application_id) if reviewer_id == voiceover_application.author_id: raise Exception('Applicants are not allowed to review their own ' 'voiceover application.') reviewer = user_services.UserActionsInfo(user_id=reviewer_id) voiceover_application.accept(reviewer_id) _save_voiceover_applications([voiceover_application]) if voiceover_application.target_type == feconf.ENTITY_TYPE_EXPLORATION: rights_manager.assign_role_for_exploration( reviewer, voiceover_application.target_id, voiceover_application.author_id, rights_domain.ROLE_VOICE_ARTIST) opportunity_services.update_exploration_voiceover_opportunities( voiceover_application.target_id, voiceover_application.language_code) opportunities = ( opportunity_services.get_exploration_opportunity_summaries_by_ids( [voiceover_application.target_id])) email_manager.send_accepted_voiceover_application_email( voiceover_application.author_id, opportunities[voiceover_application.target_id].chapter_title, voiceover_application.language_code) # TODO(#7969): Add notification to the user's dashboard for the accepted # voiceover application. voiceover_application_models = ( suggestion_models.GeneralVoiceoverApplicationModel. get_voiceover_applications(voiceover_application.target_type, voiceover_application.target_id, voiceover_application.language_code)) rejected_voiceover_applications = [] for model in voiceover_application_models: voiceover_application = _get_voiceover_application_from_model(model) if not voiceover_application.is_handled: voiceover_application.reject( reviewer_id, 'We have to reject your application as another ' 'application for the same opportunity got accepted.') rejected_voiceover_applications.append(voiceover_application) _save_voiceover_applications(rejected_voiceover_applications)
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 setUp(self): """Completes the sign-up process for the various users.""" super(BaseTopicEditorControllerTest, self).setUp() self.signup(self.TOPIC_MANAGER_EMAIL, self.TOPIC_MANAGER_USERNAME) self.signup(self.NEW_USER_EMAIL, self.NEW_USER_USERNAME) self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.topic_manager_id = self.get_user_id_from_email( self.TOPIC_MANAGER_EMAIL) self.new_user_id = self.get_user_id_from_email(self.NEW_USER_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.set_topic_managers([self.TOPIC_MANAGER_USERNAME]) self.topic_manager = user_services.UserActionsInfo( self.topic_manager_id) self.admin = user_services.UserActionsInfo(self.admin_id) self.new_user = user_services.UserActionsInfo(self.new_user_id) self.topic_id = topic_services.get_new_topic_id() self.save_new_topic(self.topic_id, self.admin_id, 'Name', 'Description', [], [], [], [])
def setUp(self): super(TopicFetchersUnitTests, self).setUp() self.TOPIC_ID = topic_services.get_new_topic_id() changelist = [topic_domain.TopicChange({ 'cmd': topic_domain.CMD_ADD_SUBTOPIC, 'title': 'Title', 'subtopic_id': 1 })] self.save_new_topic( self.TOPIC_ID, self.user_id, name='Name', abbreviated_name='name', url_fragment='name-one', description='Description', canonical_story_ids=[self.story_id_1, self.story_id_2], additional_story_ids=[self.story_id_3], uncategorized_skill_ids=[self.skill_id_1, self.skill_id_2], subtopics=[], next_subtopic_id=1) self.save_new_story(self.story_id_1, self.user_id, self.TOPIC_ID) self.save_new_story( self.story_id_3, self.user_id, self.TOPIC_ID, title='Title 3', description='Description 3') self.signup('*****@*****.**', 'A') self.signup('*****@*****.**', 'B') self.signup(self.ADMIN_EMAIL, 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) topic_services.update_topic_and_subtopic_pages( self.user_id_admin, self.TOPIC_ID, changelist, 'Added a subtopic') self.topic = topic_fetchers.get_topic_by_id(self.TOPIC_ID) 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 test_can_manage_topic_rights(self, topic_id, **kwargs): if not self.user_id: raise self.NotLoggedInException user_actions_info = user_services.UserActionsInfo(self.user_id) if (role_services.ACTION_MANAGE_TOPIC_RIGHTS in user_actions_info.actions): return handler(self, topic_id, **kwargs) else: raise self.UnauthorizedUserException( '%s does not have enough rights to assign roles for the ' 'topic.' % self.user_id)
def setUp(self): """Completes the sign-up process for the various users.""" super(BaseTopicEditorControllerTests, self).setUp() self.signup(self.TOPIC_MANAGER_EMAIL, self.TOPIC_MANAGER_USERNAME) self.signup(self.NEW_USER_EMAIL, self.NEW_USER_USERNAME) self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.topic_manager_id = self.get_user_id_from_email( self.TOPIC_MANAGER_EMAIL) self.new_user_id = self.get_user_id_from_email(self.NEW_USER_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.set_topic_managers([self.TOPIC_MANAGER_USERNAME]) self.topic_manager = user_services.UserActionsInfo( self.topic_manager_id) self.admin = user_services.UserActionsInfo(self.admin_id) self.new_user = user_services.UserActionsInfo(self.new_user_id) self.skill_id = skill_services.get_new_skill_id() self.save_new_skill(self.skill_id, self.admin_id, 'Skill Description') self.skill_id_2 = skill_services.get_new_skill_id() self.save_new_skill(self.skill_id_2, self.admin_id, 'Skill Description 2') self.topic_id = topic_services.get_new_topic_id() self.save_new_topic(self.topic_id, self.admin_id, 'Name', 'Description', [], [], [self.skill_id, self.skill_id_2], [], 1) changelist = [ topic_domain.TopicChange({ 'cmd': topic_domain.CMD_ADD_SUBTOPIC, 'title': 'Title', 'subtopic_id': 1 }) ] topic_services.update_topic_and_subtopic_pages(self.admin_id, self.topic_id, changelist, 'Added subtopic.')
def setUp(self): super(SubscriptionsTest, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) self.signup(self.VIEWER_EMAIL, self.VIEWER_USERNAME) self.signup(self.OWNER_2_EMAIL, self.OWNER2_USERNAME) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL) self.viewer_id = self.get_user_id_from_email(self.VIEWER_EMAIL) self.owner_2_id = self.get_user_id_from_email(self.OWNER_2_EMAIL) self.owner = user_services.UserActionsInfo(self.owner_id)
def setUp(self): super(CollectionNodeMetadataDictsTest, self).setUp() self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL) self.signup(self.ALBERT_EMAIL, self.ALBERT_NAME) self.bob_id = self.get_user_id_from_email(self.BOB_EMAIL) self.signup(self.BOB_EMAIL, self.BOB_NAME) self.albert = user_services.UserActionsInfo(self.albert_id) self.bob = user_services.UserActionsInfo(self.bob_id) self.save_new_valid_exploration(self.EXP_ID1, self.albert_id, title='Exploration 1 Albert title', objective='An objective 1') self.save_new_valid_exploration(self.EXP_ID2, self.albert_id, title='Exploration 2 Albert title', objective='An objective 2') self.save_new_valid_exploration(self.EXP_ID3, self.albert_id, title='Exploration 3 Albert title', objective='An objective 3') self.save_new_valid_exploration(self.EXP_ID4, self.bob_id, title='Exploration 4 Bob title', objective='An objective 4') self.save_new_valid_exploration(self.EXP_ID5, self.albert_id, title='Exploration 5 Albert title', objective='An objective 5') rights_manager.publish_exploration(self.albert, self.EXP_ID1) rights_manager.publish_exploration(self.albert, self.EXP_ID2) rights_manager.publish_exploration(self.albert, self.EXP_ID3) rights_manager.publish_exploration(self.bob, self.EXP_ID4) exp_services.index_explorations_given_ids([ self.EXP_ID1, self.EXP_ID2, self.EXP_ID3, self.EXP_ID4])
def test_can_view_any_topic_editor(self, **kwargs): if not self.user_id: raise self.NotLoggedInException user_actions_info = user_services.UserActionsInfo(self.user_id) if (role_services.ACTION_VISIT_ANY_TOPIC_EDITOR in user_actions_info.actions): return handler(self, **kwargs) else: raise self.UnauthorizedUserException( '%s does not have enough rights to access the topics and skills' ' dashboard.' % self.user_id)
def test_can_access_topics_and_skills_dashboard(self, **kwargs): if not self.user_id: raise self.NotLoggedInException user_actions_info = user_services.UserActionsInfo(self.user_id) if (role_services.ACTION_ACCESS_TOPICS_AND_SKILLS_DASHBOARD in user_actions_info.actions): return handler(self, **kwargs) else: raise self.UnauthorizedUserException( '%s does not have enough rights to access the topics and skills' ' dashboard.' % self.user_id)
def test_can_change_topic_publication_status(self, **kwargs): if not self.user_id: raise self.NotLoggedInException user_actions_info = user_services.UserActionsInfo(self.user_id) if (role_services.ACTION_CHANGE_TOPIC_STATUS in user_actions_info.actions): return handler(self, **kwargs) else: raise self.UnauthorizedUserException( '%s does not have enough rights to publish or unpublish the ' 'topic.' % self.user_id)
def setUp(self): """Completes the sign-up process for the various users.""" super(BaseReviewTestsControllerTests, self).setUp() self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.VIEWER_EMAIL, self.VIEWER_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.viewer_id = self.get_user_id_from_email(self.VIEWER_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.admin = user_services.UserActionsInfo(self.admin_id) self.topic_id = 'topic_id' self.story_id_1 = 'story_id_1' self.story_id_2 = 'story_id_2' self.node_id = 'node_1' self.node_id_2 = 'node_2' self.exp_id = 'exp_id' self.save_new_valid_exploration(self.exp_id, self.owner_id) self.publish_exploration(self.owner_id, self.exp_id) self.node_1 = { 'id': self.node_id, 'title': 'Title 1', 'destination_node_ids': [], 'acquired_skill_ids': ['skill_id_1', 'skill_id_2'], 'prerequisite_skill_ids': [], 'outline': '', 'outline_is_finalized': False, 'exploration_id': self.exp_id } self.story = story_domain.Story.create_default_story( self.story_id_1, 'Public Story Title', self.topic_id) self.story.story_contents.nodes = [ story_domain.StoryNode.from_dict(self.node_1) ] self.story.story_contents.initial_node_id = self.node_id self.story.story_contents.next_node_id = self.node_id_2 story_services.save_new_story(self.admin_id, self.story) self.story_2 = story_domain.Story.create_default_story( self.story_id_2, 'Private Story Title', self.topic_id) story_services.save_new_story(self.admin_id, self.story_2) story_services.publish_story(self.story_id_1, self.admin_id) self.login(self.VIEWER_EMAIL)
def setUp(self): super(BaseSubtopicViewerControllerTests, 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_id' self.subtopic_id = 1 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': self.subtopic_id, 'title': 'Sample' })] ) self.content_ids_to_audio_translations_dict = { 'content': { 'en': { 'filename': 'test.mp3', 'file_size_bytes': 100, 'needs_update': False } } } self.expected_page_contents_dict = { 'content_ids_to_audio_translations': self.content_ids_to_audio_translations_dict, 'subtitled_html': { 'content_id': 'content', 'html': 'hello world' } } self.subtopic_page.update_page_contents_html({ 'html': 'hello world', 'content_id': 'content' }) self.subtopic_page.update_page_contents_audio( self.content_ids_to_audio_translations_dict) subtopic_page_services.save_subtopic_page( self.user_id, self.subtopic_page, 'Updated page contents', [subtopic_page_domain.SubtopicPageChange({ 'cmd': subtopic_page_domain.CMD_UPDATE_SUBTOPIC_PAGE_PROPERTY, 'subtopic_id': self.subtopic_id, 'property_name': 'page_contents_html', 'new_value': 'a', 'old_value': 'b' })] )
def setUp(self): super(QuestionFetchersUnitTests, self).setUp() self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.editor_id = self.get_user_id_from_email( self.EDITOR_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.admin = user_services.UserActionsInfo(self.admin_id) self.editor = user_services.UserActionsInfo(self.editor_id) self.save_new_skill( 'skill_1', self.admin_id, description='Skill Description 1') self.save_new_skill( 'skill_2', self.admin_id, description='Skill Description 2') self.question_id = question_services.get_new_question_id() self.question = self.save_new_question( self.question_id, self.editor_id, self._create_valid_question_data('ABC'), ['skill_1'])
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 get(self, skill_id): """Returns whether the user can edit the description of a skill.""" skill_domain.Skill.require_valid_skill_id(skill_id) user_actions_info = user_services.UserActionsInfo(self.user_id) can_edit_skill_description = check_can_edit_skill_description( user_actions_info) self.values.update({ 'can_edit_skill_description': can_edit_skill_description, 'skill_id': skill_id }) self.render_json(self.values)
def put(self, topic_id, assignee_id): """Assign topic manager role to a user for a particular topic, if the user has general topic manager rights. """ topic_domain.Topic.require_valid_topic_id(topic_id) if assignee_id is None: raise self.InvalidInputException( Exception('Expected a valid assignee id to be provided.')) assignee_actions_info = user_services.UserActionsInfo(assignee_id) user_actions_info = user_services.UserActionsInfo(self.user_id) try: topic_services.assign_role( user_actions_info, assignee_actions_info, topic_domain.ROLE_MANAGER, topic_id) except Exception as e: raise self.UnauthorizedUserException(e) self.values.update({ 'role_updated': True }) self.render_json(self.values)
def setUp(self): super(CheckCanUnpublishActivityTest, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME) self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME) self.admin_id = self.get_user_id_from_email(self.ADMIN_EMAIL) self.moderator_id = self.get_user_id_from_email(self.MODERATOR_EMAIL) self.set_admins([self.ADMIN_USERNAME]) self.set_moderators([self.MODERATOR_USERNAME]) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.admin = user_services.UserActionsInfo(self.admin_id) self.owner = user_services.UserActionsInfo(self.owner_id) self.moderator = user_services.UserActionsInfo(self.moderator_id) self.save_new_valid_exploration(self.published_exp_id, self.owner_id) self.save_new_valid_exploration(self.private_exp_id, self.owner_id) self.save_new_valid_collection(self.published_col_id, self.owner_id, exploration_id=self.published_col_id) self.save_new_valid_collection(self.private_col_id, self.owner_id, exploration_id=self.private_col_id) rights_manager.publish_exploration(self.owner, self.published_exp_id) rights_manager.publish_collection(self.owner, self.published_col_id)
def setUp(self): super(TopicFetchersUnitTests, self).setUp() self.TOPIC_ID = topic_services.get_new_topic_id() changelist = [ topic_domain.TopicChange({ 'cmd': topic_domain.CMD_ADD_SUBTOPIC, 'title': 'Title', 'subtopic_id': 1 }) ] 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, self.skill_id_2], [], 1) self.save_new_story(self.story_id_1, self.user_id, 'Title', 'Description', 'Notes', self.TOPIC_ID) self.save_new_story(self.story_id_3, self.user_id, 'Title 3', 'Description 3', 'Notes', self.TOPIC_ID) 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) topic_services.update_topic_and_subtopic_pages(self.user_id_admin, self.TOPIC_ID, changelist, 'Added a subtopic') self.topic = topic_fetchers.get_topic_by_id(self.TOPIC_ID) 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(DeleteExplorationTest, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.MODERATOR_EMAIL, self.MODERATOR_USERNAME) self.set_moderators([self.MODERATOR_USERNAME]) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.owner = user_services.UserActionsInfo(self.owner_id) self.testapp = webtest.TestApp( webapp2.WSGIApplication( [webapp2.Route('/mock/<exploration_id>', self.MockHandler)], debug=feconf.DEBUG, )) self.save_new_valid_exploration(self.published_exp_id, self.owner_id) self.save_new_valid_exploration(self.private_exp_id, self.owner_id) rights_manager.publish_exploration(self.owner, self.published_exp_id)
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 setUp(self): super(UserSubscriptionsModelValidatorTests, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(USER_EMAIL, USER_NAME) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.user_id = self.get_user_id_from_email(USER_EMAIL) self.owner = user_services.UserActionsInfo(self.owner_id) explorations = [exp_domain.Exploration.create_default_exploration( '%s' % i, title='title %d' % i, category='category%d' % i ) for i in xrange(3)] for exp in explorations: exp_services.save_new_exploration(self.owner_id, exp) rights_manager.publish_exploration(self.owner, exp.id) collections = [collection_domain.Collection.create_default_collection( '%s' % i, title='title %d' % i, category='category%d' % i ) for i in xrange(3, 6)] for collection in collections: collection_services.save_new_collection(self.owner_id, collection) rights_manager.publish_collection(self.owner, collection.id) thread_id = feedback_services.create_thread( 'exploration', 'exp_id', None, 'a subject', 'some text') subscription_services.subscribe_to_thread( self.user_id, thread_id) subscription_services.subscribe_to_creator(self.user_id, self.owner_id) for exp in explorations: subscription_services.subscribe_to_exploration( self.user_id, exp.id) for collection in collections: subscription_services.subscribe_to_collection( self.user_id, collection.id) self.process_and_flush_pending_tasks() prod_validation_jobs_one_off.MODEL_TO_VALIDATOR_MAPPING = { user_models.UserSubscriptionsModel: prod_validation_jobs_one_off.UserSubscriptionsModelValidator, }
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', 'public-topic-name', 'description') self.topic.subtopics.append( topic_domain.Subtopic( 1, 'subtopic_name', [self.skill_id1], 'image.svg', constants.ALLOWED_THUMBNAIL_BG_COLORS['subtopic'][0], '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], 'subtopic-name-two')) self.topic.next_subtopic_id = 3 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') 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): 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') 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_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 test_guest_can_fetch_public_exploration_metadata_dicts(self): new_guest_user = user_services.UserActionsInfo() metadata_dicts = summary_services.get_exploration_metadata_dicts( [self.EXP_ID3, self.EXP_ID4], new_guest_user) expected_metadata_dicts = [{ 'id': self.EXP_ID3, 'objective': u'An objective 3', 'title': u'Exploration 3 Albert title', }, { 'id': self.EXP_ID4, 'objective': u'An objective 4', 'title': u'Exploration 4 Bob title', }] self.assertEqual(metadata_dicts, expected_metadata_dicts)
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 get(self, skill_id): """Returns the SkillRights object of a skill.""" skill_domain.Skill.require_valid_skill_id(skill_id) skill_rights = skill_services.get_skill_rights(skill_id, strict=False) user_actions_info = user_services.UserActionsInfo(self.user_id) can_edit_skill_description = check_can_edit_skill_description( user_actions_info) self.values.update({ 'skill_is_private': skill_rights.skill_is_private, 'creator_id': skill_rights.creator_id, 'can_edit_skill_description': can_edit_skill_description, 'skill_id': skill_id }) self.render_json(self.values)
def setUp(self): super(SuggestionMigrationOneOffJobTest, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(self.EDITOR_EMAIL, self.EDITOR_USERNAME) self.signup(self.AUTHOR_EMAIL, 'author') self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.editor_id = self.get_user_id_from_email(self.EDITOR_EMAIL) self.author_id = self.get_user_id_from_email(self.AUTHOR_EMAIL) self.editor = user_services.UserActionsInfo(self.editor_id) # Login and create exploration and suggestions. self.login(self.EDITOR_EMAIL) # Create exploration. self.save_new_valid_exploration(self.EXP_ID, self.editor_id, title='Exploration for suggestions', category='Algebra', objective='Test a suggestion.') exploration = exp_services.get_exploration_by_id(self.EXP_ID) init_state = exploration.states[exploration.init_state_name] init_interaction = init_state.interaction init_interaction.default_outcome.dest = exploration.init_state_name self.old_content = state_domain.SubtitledHtml('content', 'old content').to_dict() exp_services.update_exploration(self.editor_id, self.EXP_ID, [ exp_domain.ExplorationChange({ 'cmd': exp_domain.CMD_ADD_STATE, 'state_name': 'State 1', }), exp_domain.ExplorationChange({ 'cmd': exp_domain.CMD_EDIT_STATE_PROPERTY, 'state_name': 'State 1', 'property_name': exp_domain.STATE_PROPERTY_CONTENT, 'new_value': self.old_content }) ], 'Add state name') rights_manager.publish_exploration(self.editor, self.EXP_ID) rights_manager.assign_role_for_exploration(self.editor, self.EXP_ID, self.owner_id, rights_manager.ROLE_EDITOR)