Exemple #1
0
    def test_publish_and_unpublish_story(self):
        self.save_new_story(
            'public_story', self.USER_ID, 'Title', 'Description', 'Notes'
        )
        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, 'public_story', changelist,
            'Added node.')
        self.save_new_default_exploration(
            'exp_id', self.user_id_a, title='title')
        self.publish_exploration(self.user_id_a, 'exp_id')
        change_list = [story_domain.StoryChange({
            'cmd': story_domain.CMD_UPDATE_STORY_NODE_PROPERTY,
            'property_name': (
                story_domain.STORY_NODE_PROPERTY_EXPLORATION_ID),
            'node_id': 'node_1',
            'old_value': None,
            'new_value': 'exp_id'
        })]
        story_services.update_story(
            self.USER_ID, 'public_story', change_list, 'Updated story node.')
        story_rights = story_services.get_story_rights('public_story')
        self.assertFalse(story_rights.story_is_published)
        story_services.publish_story('public_story', self.user_id_admin)

        with self.assertRaisesRegexp(
            Exception,
            'The user does not have enough rights to unpublish the story.'):
            story_services.unpublish_story('public_story', self.user_id_a)
Exemple #2
0
 def test_publish_story_with_no_exploration_id(self):
     story_rights = story_services.get_story_rights(self.STORY_ID)
     self.assertFalse(story_rights.story_is_published)
     with self.assertRaisesRegexp(
         Exception,
         'Story node with id node_1 does not contain an exploration id.'):
         story_services.publish_story(self.STORY_ID, self.user_id_admin)
Exemple #3
0
 def test_reassigning_none_role_to_same_user(self):
     with self.assertRaisesRegexp(
             Exception, 'This user already has no role for this story'):
         story_services.assign_role(self.user_admin, self.user_a,
                                    story_domain.ROLE_NONE, self.STORY_ID)
     story_rights = story_services.get_story_rights(self.STORY_ID)
     self.assertFalse(
         story_services.check_can_edit_story(self.user_a, story_rights))
Exemple #4
0
    def test_create_new_story_rights(self):
        story_services.assign_role(self.user_admin, self.user_a,
                                   story_domain.ROLE_MANAGER, self.STORY_ID)

        story_rights = story_services.get_story_rights(self.STORY_ID)

        self.assertTrue(
            story_services.check_can_edit_story(self.user_a, story_rights))
        self.assertFalse(
            story_services.check_can_edit_story(self.user_b, story_rights))
Exemple #5
0
    def test_non_admin_cannot_assign_roles(self):
        with self.assertRaisesRegexp(
                Exception,
                'UnauthorizedUserException: Could not assign new role.'):
            story_services.assign_role(self.user_b, self.user_a,
                                       story_domain.ROLE_MANAGER,
                                       self.STORY_ID)

        story_rights = story_services.get_story_rights(self.STORY_ID)
        self.assertFalse(
            story_services.check_can_edit_story(self.user_a, story_rights))
        self.assertFalse(
            story_services.check_can_edit_story(self.user_b, story_rights))
Exemple #6
0
    def test_reassigning_manager_role_to_same_user(self):
        story_services.assign_role(self.user_admin, self.user_a,
                                   story_domain.ROLE_MANAGER, self.STORY_ID)
        with self.assertRaisesRegexp(
                Exception, 'This user already is a manager for this story'):
            story_services.assign_role(self.user_admin, self.user_a,
                                       story_domain.ROLE_MANAGER,
                                       self.STORY_ID)

        story_rights = story_services.get_story_rights(self.STORY_ID)
        self.assertTrue(
            story_services.check_can_edit_story(self.user_a, story_rights))
        self.assertFalse(
            story_services.check_can_edit_story(self.user_b, story_rights))
 def test_publish_story_with_private_exploration(self):
     self.save_new_story('private_story', self.USER_ID, 'Title',
                         'Description', 'Notes', self.TOPIC_ID)
     topic_services.add_canonical_story(self.USER_ID, self.TOPIC_ID,
                                        'private_story')
     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, 'private_story', changelist,
                                 'Added node.')
     self.save_new_default_exploration('exp_id',
                                       self.user_id_a,
                                       title='title')
     change_list = [
         story_domain.StoryChange({
             'cmd':
             story_domain.CMD_UPDATE_STORY_NODE_PROPERTY,
             'property_name':
             (story_domain.STORY_NODE_PROPERTY_EXPLORATION_ID),
             'node_id':
             self.NODE_ID_1,
             'old_value':
             None,
             'new_value':
             'exp_id'
         })
     ]
     story_services.update_story(self.USER_ID, 'private_story', change_list,
                                 'Updated story node.')
     story_rights = story_services.get_story_rights('private_story')
     self.assertFalse(story_rights.story_is_published)
     with self.assertRaisesRegexp(
             Exception, 'Exploration with id exp_id isn\'t published.'):
         story_services.publish_story('private_story', self.user_id_admin)
Exemple #8
0
    def test_admin_can_manage_story(self):
        story_rights = story_services.get_story_rights(self.STORY_ID)

        self.assertTrue(
            story_services.check_can_edit_story(self.user_admin, story_rights))