예제 #1
0
    def test_nameless_step(self):
        """ should rename properly a nameless step """

        support.create_project(self, 'columbia-heights')
        project = cauldron.project.get_internal_project()
        project.naming_scheme = None

        support.add_step(self)
        support.add_step(self)

        r = Response()
        with patch('cauldron.session.naming.explode_filename') as func:
            func.return_value = dict(
                extension='py',
                index=1,
                name=''
            )
            step_actions.modify_step(
                response=r,
                project=project,
                name=project.steps[0].filename,
                new_name='',
                position=2
            )

        self.assertFalse(r.failed)
예제 #2
0
    def test_no_existing_source_file(self):
        """ should succeed even if the step has no source file """

        support.create_project(self, 'richfield')
        support.add_step(self, 'first')

        project = cauldron.project.get_internal_project()
        step = project.steps[0]
        r = Response()

        self.assertTrue(
            systems.remove(step.source_path),
            'should have removed source file'
        )

        result = step_actions.modify_step(
            response=r,
            project=project,
            name=step.filename,
            new_name='solo',
            title='Only Step'
        )

        new_step = project.steps[0]
        self.assertTrue(result)
        self.assertTrue(os.path.exists(new_step.source_path))
예제 #3
0
    def test_nameless_step(self):
        """ should rename properly a nameless step """

        support.create_project(self, 'columbia-heights')
        project = cauldron.project.get_internal_project()
        project.naming_scheme = None

        support.add_step(self)
        support.add_step(self)

        r = Response()
        with patch('cauldron.session.naming.explode_filename') as func:
            func.return_value = dict(extension='py', index=1, name='')
            step_actions.modify_step(response=r,
                                     project=project,
                                     name=project.steps[0].filename,
                                     new_name='',
                                     position=2)

        self.assertFalse(r.failed)
예제 #4
0
    def test_change_title(self):
        """ should change title """

        support.create_project(self, 'blaine')
        support.add_step(self)

        project = cauldron.project.get_internal_project()

        r = Response()
        step_actions.modify_step(response=r,
                                 project=project,
                                 name=project.steps[0].filename,
                                 title='a')
        self.assertFalse(r.failed)
        self.assertEqual(project.steps[0].definition.title, 'a')

        r = Response()
        step_actions.modify_step(response=r,
                                 project=project,
                                 name=project.steps[0].filename,
                                 title='b')
        self.assertFalse(r.failed)
        self.assertEqual(project.steps[0].definition.title, 'b')

        r = Response()
        step_actions.modify_step(response=r,
                                 project=project,
                                 name=project.steps[0].filename,
                                 new_name='first')
        self.assertFalse(r.failed)
        self.assertEqual(project.steps[0].definition.title, 'b')
예제 #5
0
    def test_fail_remove_old_step(self):
        """ should fail if unable to remove the old step """

        support.create_project(self, 'bloomington')
        support.add_step(self, 'first')

        project = cauldron.project.get_internal_project()
        step = project.steps[0]
        r = Response()

        with patch.object(project, 'remove_step') as remove_step:
            remove_step.return_value = None
            result = step_actions.modify_step(r, project, step.filename)

        self.assertFalse(result)
        self.assert_has_error_code(r, 'NO_SUCH_STEP')
예제 #6
0
    def test_fail_remove_old_step(self):
        """ should fail if unable to remove the old step """

        support.create_project(self, 'bloomington')
        support.add_step(self, 'first')

        project = cauldron.project.get_internal_project()
        step = project.steps[0]
        r = Response()

        with patch.object(project, 'remove_step') as remove_step:
            remove_step.return_value = None
            result = step_actions.modify_step(r, project, step.filename)

        self.assertFalse(result)
        self.assert_has_error_code(r, 'NO_SUCH_STEP')
예제 #7
0
    def test_move_step_later(self):
        """ should move step later in the project """

        support.create_project(self, 'edina')
        support.add_step(self, 'first')
        support.add_step(self, 'second')
        support.add_step(self, 'third')

        project = cauldron.project.get_internal_project()

        r = Response()
        result = step_actions.modify_step(response=r,
                                          project=project,
                                          name=project.steps[0].filename,
                                          position='3')

        self.assertTrue(result)
        self.assertGreater(project.steps[0].filename.find('second'), 0)
        self.assertGreater(project.steps[1].filename.find('third'), 0)
        self.assertGreater(project.steps[2].filename.find('first'), 0)
예제 #8
0
    def test_move_step_later(self):
        """ should move step later in the project """

        support.create_project(self, 'edina')
        support.add_step(self, 'first')
        support.add_step(self, 'second')
        support.add_step(self, 'third')

        project = cauldron.project.get_internal_project()

        r = Response()
        result = step_actions.modify_step(
            response=r,
            project=project,
            name=project.steps[0].filename,
            position='3'
        )

        self.assertTrue(result)
        self.assertGreater(project.steps[0].filename.find('second'), 0)
        self.assertGreater(project.steps[1].filename.find('third'), 0)
        self.assertGreater(project.steps[2].filename.find('first'), 0)
예제 #9
0
    def test_no_existing_source_file(self):
        """ should succeed even if the step has no source file """

        support.create_project(self, 'richfield')
        support.add_step(self, 'first')

        project = cauldron.project.get_internal_project()
        step = project.steps[0]
        r = Response()

        self.assertTrue(systems.remove(step.source_path),
                        'should have removed source file')

        result = step_actions.modify_step(response=r,
                                          project=project,
                                          name=step.filename,
                                          new_name='solo',
                                          title='Only Step')

        new_step = project.steps[0]
        self.assertTrue(result)
        self.assertTrue(os.path.exists(new_step.source_path))
예제 #10
0
    def test_change_title(self):
        """ should change title """

        support.create_project(self, 'blaine')
        support.add_step(self)

        project = cauldron.project.get_internal_project()

        r = Response()
        step_actions.modify_step(
            response=r,
            project=project,
            name=project.steps[0].filename,
            title='a'
        )
        self.assertFalse(r.failed)
        self.assertEqual(project.steps[0].definition.title, 'a')

        r = Response()
        step_actions.modify_step(
            response=r,
            project=project,
            name=project.steps[0].filename,
            title='b'
        )
        self.assertFalse(r.failed)
        self.assertEqual(project.steps[0].definition.title, 'b')

        r = Response()
        step_actions.modify_step(
            response=r,
            project=project,
            name=project.steps[0].filename,
            new_name='first'
        )
        self.assertFalse(r.failed)
        self.assertEqual(project.steps[0].definition.title, 'b')
예제 #11
0
파일: __init__.py 프로젝트: sernst/cauldron
def execute(
        context: cli.CommandContext,
        action: str = None,
        step_name: str = None,
        position: str = None,
        title: str = None,
        new_name: str = None,
        keep: bool = False,
        project: 'projects.Project' = None
) -> Response:
    """

    :return:
    """

    response = context.response

    project = (
        project
        if project else
        cauldron.project.internal_project
    )

    if not project:
        return response.fail(
            code='NO_OPEN_PROJECT',
            message='No project is open. Step commands require an open project'
        ).console(
            whitespace=1
        ).response

    if not action or action == 'list':
        actions.echo_steps(response, project)
        return response

    if action == 'add' and not step_name:
            step_name = ''
    elif not step_name:
        return response.fail(
            code='NO_STEP_NAME',
            message='A step name is required for this command'
        ).console(
            whitespace=1
        ).response

    step_name = step_name.strip('"')

    if action == 'add':
        return actions.create_step(
            response=response,
            project=project,
            name=step_name,
            position=position,
            title=title.strip('"') if title else title
        )

    if action == 'modify':
        actions.modify_step(
            response=response,
            project=project,
            name=step_name,
            new_name=new_name,
            title=title,
            position=position
        )
        return response

    if action == 'remove':
        return removal.remove_step(
            response=response,
            project=project,
            name=step_name,
            keep_file=keep
        )

    if action == 'unmute':
        actions.toggle_muting(
            response=response,
            project=project,
            step_name=step_name,
            value=False
        )
        return response

    if action == 'mute':
        actions.toggle_muting(
            response=response,
            project=project,
            step_name=step_name,
            value=True
        )
        return response
예제 #12
0
def execute(context: cli.CommandContext,
            action: str = None,
            step_name: str = None,
            position: str = None,
            title: str = None,
            new_name: str = None,
            keep: bool = False,
            project: 'projects.Project' = None) -> Response:
    """

    :return:
    """

    response = context.response

    project = (project if project else cauldron.project.internal_project)

    if not project:
        return response.fail(
            code='NO_OPEN_PROJECT',
            message='No project is open. Step commands require an open project'
        ).console(whitespace=1).response

    if not action or action == 'list':
        actions.echo_steps(response, project)
        return response

    if action == 'add' and not step_name:
        step_name = ''
    elif not step_name:
        return response.fail(
            code='NO_STEP_NAME',
            message='A step name is required for this command').console(
                whitespace=1).response

    step_name = step_name.strip('"')

    if action == 'add':
        return actions.create_step(response=response,
                                   project=project,
                                   name=step_name,
                                   position=position,
                                   title=title.strip('"') if title else title)

    if action == 'modify':
        actions.modify_step(response=response,
                            project=project,
                            name=step_name,
                            new_name=new_name,
                            title=title,
                            position=position)
        return response

    if action == 'remove':
        return removal.remove_step(response=response,
                                   project=project,
                                   name=step_name,
                                   keep_file=keep)

    if action == 'unmute':
        actions.toggle_muting(response=response,
                              project=project,
                              step_name=step_name,
                              value=False)
        return response

    if action == 'mute':
        actions.toggle_muting(response=response,
                              project=project,
                              step_name=step_name,
                              value=True)
        return response