def test_get_all_pipelines(self):
        projecta = self.create_project()
        projectb = self.create_project(name=u"ProjectB")
        projectc = self.create_project(name=u"ProjectC")

        repository = PipelineRepository()
        created_pipeline = repository.create(name=u"Test Pipeline", pipeline_definition="ProjectA > ProjectB")
        created_pipeline2 = repository.create(
            name=u"Test Pipeline 2", pipeline_definition="ProjectB > ProjectA > ProjectC"
        )

        pipelines = repository.get_all()

        self.assertEqual(len(pipelines), 2)
        self.assertEqual(pipelines[0].name, u"Test Pipeline")
        self.assertEqual(pipelines[1].name, u"Test Pipeline 2")
        self.assertEqual(len(pipelines[0].items), 2)
        self.assertEqual(len(pipelines[1].items), 3)

        self.assertNotEqual(pipelines[0].items[0].project, None)
        self.assertNotEqual(pipelines[0].items[1].project, None)
        self.assertEqual(pipelines[0].items[0].project.id, projecta.id)
        self.assertEqual(pipelines[0].items[1].project.id, projectb.id)

        self.assertNotEqual(pipelines[1].items[0].project, None)
        self.assertNotEqual(pipelines[1].items[1].project, None)
        self.assertNotEqual(pipelines[1].items[2].project, None)
        self.assertEqual(pipelines[1].items[0].project.id, projectb.id)
        self.assertEqual(pipelines[1].items[1].project.id, projecta.id)
        self.assertEqual(pipelines[1].items[2].project.id, projectc.id)
    def test_delete_pipeline(self):
        projecta = self.create_project()
        projectb = self.create_project(name=u"ProjectB")

        repository = PipelineRepository()
        created_pipeline = repository.create(name=u"Test Pipeline", pipeline_definition="ProjectA > ProjectB")

        repository.delete(created_pipeline.id)

        pipelines = repository.get_all()
        self.assertEqual(len(pipelines), 0)
Exemple #3
0
class PipelineController(BaseController):
    def __init__(self):
        self.repository = PipelineRepository()

    @template.output("pipeline_index.html")
    def index(self):
        pipelines = self.repository.get_all()
        return template.render(authenticated=self.authenticated(), pipeline=None, pipelines=pipelines, errors=None)

    @authenticated()
    @template.output("pipeline_index.html")
    def create(self, name, pipeline_definition):
        try:
            pipeline = self.repository.create(name, pipeline_definition)
            PluginEvents.on_pipeline_created(pipeline)
            raise cherrypy.HTTPRedirect("/pipeline")
        except (ProjectNotFoundError, CyclicalPipelineError), err:
            pipelines = self.repository.get_all()
            return template.render(
                authenticated=self.authenticated(), pipelines=pipelines, pipeline=None, errors=[err.message]
            ) | HTMLFormFiller(data=locals())