def test_build_successfully(self):
        project_repo = ProjectRepository()
        project = project_repo.create("pyoc", "nosetests", "git://github.com/heynemann/pyoc.git")
        repo_path = join(root_path, "tests", "functional", "repo")
        
        try:
            shutil.rmtree(repo_path)
        except:
            print "The repository folder for the test didn't exist previously. This is not an error!"
            
        service = BuildService(base_path=repo_path)
        
        build = service.build_project(project.id)

        self.failUnless(build.scm_status == ScmResult.Created or build.scm_status == ScmResult.Updated)
    def test_build_successfully(self):
        project = self.create_project(name="pyoc", build_script="nosetests", scm_repository="git://github.com/heynemann/pyoc.git", monitor_changes=True)

        elixir.session.flush()
        elixir.session.commit()

        repo_path = join(root_path, "tests", "functional", "repo")
        
        try:
            shutil.rmtree(repo_path)
        except:
            print "The repository folder for the test didn't exist previously. This is not an error!"
            
        service = BuildService(base_path=repo_path)
        
        build = service.build_project(project.id)

        self.failUnless(build.scm_status == ScmResult.Created or build.scm_status == ScmResult.Updated)
    def test_build(self):
        project = Project("Test Project", "make test", "git_repo")
        execute_result = ExecuteResult(project.build_script, "Ran successfully", "", 0)
        scm_result = ScmResult(ScmResult.Created)

        repository_mock = self.mock.CreateMock(ProjectRepository)
        scm_mock = self.mock.CreateMock(GitRepository)
        executer_mock = self.mock.CreateMock(ShellExecuter)

        repository_mock.get(1).AndReturn(project)
        repository_mock.update(project)
        scm_mock.create_or_update(project).AndReturn(scm_result)
        executer_mock.execute(project.build_script).AndReturn(execute_result)
        
        self.mock.ReplayAll()
        
        service = BuildService(repository=repository_mock, scm=scm_mock, executer=executer_mock)
        
        build = service.build_project(1)
        
        self.assertEqual(build.status, BuildService.Success)
        self.mock.VerifyAll()
    def test_build(self):
        project = Project()
        project.id = 1
        project.name = "Test Project"
        project.build_script = "make test"
        project.scm_repository = "git_repo"
        project.tabs = []
        project.file_locators = []

        project2 = Project()
        project.id = 2
        project2.name = "Test Project 2"
        project2.build_script = "make test"
        project2.scm_repository = "git_repo"
        project2.tabs = []
        project2.file_locators = []

        execute_result = ExecuteResult(project.build_script, "Ran successfully", 0)
        scm_result = ScmResult(
            ScmResult.Created,
            "some/path/",
            {
                "commit_number": "1234abcd",
                "author": "Bernardo",
                "author_date": None,
                "committer": "Bernardo",
                "committer_date": None,
                "subject": "Changed some stuff",
            },
            "some log",
        )

        pipeline = Pipeline()
        pipeline.items = []
        item = PipelineItem()
        item.project = project
        pipeline.items.append(item)
        item2 = PipelineItem()
        item2.project = project2
        pipeline.items.append(item)

        repository_mock = self.mock.CreateMock(ProjectRepository)
        pipeline_repository_mock = self.mock.CreateMock(PipelineRepository)
        scm_mock = self.mock.CreateMock(GitRepository)
        executer_mock = self.mock.CreateMock(ShellExecuter)

        repository_mock.get(1).AndReturn(project)
        repository_mock.update(project, [], [])
        scm_mock.create_or_update(project).AndReturn(scm_result)
        executer_mock.execute(project.build_script, "some/path/").AndReturn(execute_result)
        pipeline_repository_mock.get_all_pipelines_for(project).AndReturn((pipeline,))

        self.mock.ReplayAll()

        service = BuildService(
            repository=repository_mock,
            pipeline_repository=pipeline_repository_mock,
            scm=scm_mock,
            executer=executer_mock,
        )

        build = service.build_project(1)

        self.assertEqual(build.status, BuildService.Success)
        self.assertEqual(build.commit_number, "1234abcd")
        self.assertEqual(build.commit_author, "Bernardo")
        self.assertEqual(build.commit_committer, "Bernardo")
        self.assertEqual(build.commit_text, "Changed some stuff")

        self.mock.VerifyAll()