Exemplo n.º 1
0
 def test_no_target(self, get_options, post):
     project = self.create_project(name='test', slug='test')
     build = self.create_build(project,
                               result=Result.failed,
                               status=Status.finished)
     build_finished_handler(build_id=build.id.hex)
     self.assertEquals(post.call_count, 0)
Exemplo n.º 2
0
    def test_nonnotifying_build(self, post):
        project1 = self.create_project(name='project1',
                                       slug='project1',
                                       notify='0')
        project2 = self.create_project(name='project2', slug='project2')
        collection_id = uuid.uuid4()
        build1 = self.create_build(project1,
                                   target='D1',
                                   collection_id=collection_id,
                                   result=Result.failed,
                                   status=Status.finished)
        build2 = self.create_build(project2,
                                   target='D1',
                                   collection_id=collection_id,
                                   result=Result.unknown,
                                   status=Status.in_progress)

        build_finished_handler(build_id=build1.id.hex)
        assert post.call_count == 0

        build2.result = Result.failed
        build2.status = Status.finished
        db.session.add(build2)
        db.session.commit()

        build_finished_handler(build_id=build2.id.hex)
        assert post.call_count == 1

        args, kwargs = post.call_args
        id, msg, request = args
        assert 'project1' not in msg
        assert 'project2' in msg
Exemplo n.º 3
0
    def test_slug_escape(self, get_options, post):
        get_options.return_value = {'phabricator.notify': '1'}
        project = self.create_project(name='Server', slug='project-(slug)')
        self.assertEquals(post.call_count, 0)
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project,
                                  result=Result.passed,
                                  target='D1',
                                  source=source,
                                  status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.passed,
        )

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/find_build/{0}/'.format(build.id.hex))

        expected_msg = 'Server build Passed {{icon check, color=green}} ([results]({0})).'
        post.assert_called_once_with('1', expected_msg.format(build_link),
                                     mock.ANY)
Exemplo n.º 4
0
    def test_slug_escape(self, get_options, phab):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='Server', slug='project-(slug)')
        self.assertEquals(phab.call_count, 0)
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project, result=Result.passed, target='D1', source=source, status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.passed,
        )

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        safe_slug = 'project-%28slug%29'
        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            safe_slug, build.id.hex))

        expected_msg = 'Server build Passed {{icon check, color=green}} ([results]({0})).'
        phab.assert_called_once_with('1', expected_msg.format(build_link))
Exemplo n.º 5
0
 def test_blacklisted_project(self, get_options, phab):
     project = self.create_project(name='test', slug='test')
     self.assertEquals(phab.call_count, 0)
     build = self.create_build(project, result=Result.failed, target='D1', status=Status.finished)
     build_finished_handler(build_id=build.id.hex)
     self.assertEquals(phab.call_count, 0)
     get_options.assert_called_once_with(project.id)
Exemplo n.º 6
0
 def test_blacklisted_project(self, get_options, phab):
     project = self.create_project(name='test', slug='test')
     self.assertEquals(phab.call_count, 0)
     build = self.create_build(project, result=Result.failed, target='D1', status=Status.finished)
     build_finished_handler(build_id=build.id.hex)
     self.assertEquals(phab.call_count, 0)
     get_options.assert_called_once_with(project.id)
Exemplo n.º 7
0
    def test_slug_escape(self, get_options, post):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='Server', slug='project-(slug)')
        self.assertEquals(post.call_count, 0)
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project, result=Result.passed, target='D1', source=source, status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.passed,
        )

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_web_uri('/find_build/{0}/'.format(build.id.hex))

        expected_msg = '(NOTE) Passing builds:\n\n - [Server]({0}).'
        post.assert_called_once_with('1', expected_msg.format(build_link), mock.ANY)
Exemplo n.º 8
0
    def test_parent_and_new_failures(self, get_options, post,
                                     get_base_failures):
        def get_test_desc(build, testcase, test_name):
            test_link = build_uri('/build_test/{0}/{1}/'.format(
                build.id.hex,
                testcase.id.hex,
            ))
            return "[%s](%s)" % (test_name, test_link)

        get_options.return_value = {'phabricator.notify': '1'}
        project = self.create_project(name='Server', slug='project-slug')
        self.assertEquals(post.call_count, 0)
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project,
                                  result=Result.failed,
                                  target='D1',
                                  source=source,
                                  status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.failed,
        )
        testcase2 = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo2',
            job=job,
            duration=134,
            result=Result.failed,
        )
        get_base_failures.return_value = {testcase.name}

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/find_build/{0}/'.format(build.id.hex))
        failure_link = build_uri('/build_tests/{0}/'.format(build.id.hex))

        test_desc = get_test_desc(build, testcase, 'test_foo')
        test_desc2 = get_test_desc(build, testcase2, 'test_foo2')
        expected_msg = """Server build Failed {{icon times, color=red}} ([results]({0})). There were 1 new [test failures]({1})

**New failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|

**Failures in parent revision (1):**
|Test Name | Package|
|--|--|
|{3}|test.group.ClassName|"""

        post.assert_called_once_with(
            '1',
            expected_msg.format(build_link, failure_link, test_desc2,
                                test_desc), mock.ANY)
Exemplo n.º 9
0
    def test_commit_coverage_posted(self, get_options, merged_coverage_data,
                                    post_diff_coverage, post_commit_coverage,
                                    post_diff_comment):
        get_options.return_value = {
            'phabricator.notify': '1',
            'phabricator.coverage': '1',
        }
        repo = self.create_repo(backend=RepositoryBackend.git)
        self.create_option(name='phabricator.callsign', value='BOO', item_id=repo.id)
        project = self.create_project(name='Server', repository=repo)
        source = self.create_source(project)
        revision_id = 12345
        build = self.create_build(project,
                                  result=Result.passed,
                                  source=source,
                                  status=Status.finished,
                                  tags=['commit'],
                                  message='commit message\nDifferential Revision: '
                                  'https://phabricator.example.com/D{}'.format(revision_id))
        job = self.create_job(build=build)

        cov = {"file": "NUC"}
        merged_coverage_data.return_value = cov

        build_finished_handler(build_id=build.id.hex)

        assert post_diff_comment.call_count == 0
        assert post_diff_coverage.call_count == 1
        post_diff_coverage.assert_called_once_with(revision_id, cov, mock.ANY)
        assert post_commit_coverage.call_count == 1
        post_commit_coverage.assert_called_once_with('BOO', 'master', source.revision_sha, cov, mock.ANY)
Exemplo n.º 10
0
    def test_multiple_builds(self, get_options, phab):
        get_options.return_value = {'phabricator.notify': '1'}
        project1 = self.create_project(name='Server', slug='project-slug')
        project2 = self.create_project(name='Server2', slug='project-slug2')
        self.assertEquals(phab.call_count, 0)
        collection_id = uuid.uuid4()

        def create_build(result, project):
            patch = self.create_patch()
            source = self.create_source(project,
                                        revision_sha='1235',
                                        patch=patch)
            build = self.create_build(project,
                                      result=result,
                                      target='D1',
                                      source=source,
                                      status=Status.finished,
                                      collection_id=collection_id)
            job = self.create_job(build=build)
            testcase = self.create_test(
                package='test.group.ClassName',
                name='test.group.ClassName.test_foo',
                job=job,
                duration=134,
                result=result,
            )
            return build, testcase

        build1, testcase1 = create_build(Result.failed, project1)
        build2, testcase2 = create_build(Result.passed, project2)

        build_finished_handler(build_id=build1.id.hex)

        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build1.project.slug, build1.id.hex))
        build2_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build2.project.slug, build2.id.hex))
        failure_link = build_uri(
            '/projects/{0}/builds/{1}/tests/?result=failed'.format(
                build1.project.slug, build1.id.hex))

        test_link = build_uri(
            '/projects/{0}/builds/{1}/jobs/{2}/tests/{3}/'.format(
                build1.project.slug, build1.id.hex, testcase1.job_id.hex,
                testcase1.id.hex))
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """Server build Failed {{icon times, color=red}} ([results]({0})). There were 1 new [test failures]({1})

**New failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|

Server2 build Passed {{icon check, color=green}} ([results]({3}))."""

        phab.assert_called_once_with(
            '1',
            expected_msg.format(build_link, failure_link, test_desc,
                                build2_link))
Exemplo n.º 11
0
    def test_multiple_builds(self, get_options, post):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project1 = self.create_project(name='Server', slug='project-slug')
        project2 = self.create_project(name='Server2', slug='project-slug2')
        self.assertEquals(post.call_count, 0)
        collection_id = uuid.uuid4()

        def create_build(result, project):
            base_source = self.create_source(project, revision_sha='1235')
            base_build = self.create_build(project, result=Result.passed,
                                           source=base_source,
                                           status=Status.finished)
            self.create_job(build=base_build)

            patch = self.create_patch()
            source = self.create_source(project, revision_sha='1235', patch=patch)
            build = self.create_build(project, result=result, target='D1', source=source, status=Status.finished, collection_id=collection_id)
            job = self.create_job(build=build)
            testcase = self.create_test(
                package='test.group.ClassName',
                name='test.group.ClassName.test_foo',
                job=job,
                duration=134,
                result=result,
                )
            return build, testcase

        build1, testcase1 = create_build(Result.failed, project1)
        build2, testcase2 = create_build(Result.passed, project2)

        build_finished_handler(build_id=build1.id.hex)

        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build1.project.slug, build1.id.hex))
        build2_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build2.project.slug, build2.id.hex))
        failure_link = build_uri('/projects/{0}/builds/{1}/tests/?result=failed'.format(
            build1.project.slug, build1.id.hex))

        test_link = build_uri('/projects/{0}/builds/{1}/jobs/{2}/tests/{3}/'.format(
            build1.project.slug,
            build1.id.hex,
            testcase1.job_id.hex,
            testcase1.id.hex
        ))
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """Server build Failed {{icon times, color=red}} ([results]({0})). There were 1 new [test failures]({1})

**New failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|

Server2 build Passed {{icon check, color=green}} ([results]({3}))."""

        post.assert_called_once_with('1', expected_msg.format(build_link, failure_link, test_desc, build2_link), mock.ANY)
Exemplo n.º 12
0
    def test_parent_and_new_failures(self, get_options, phab, get_base_failures):
        def get_test_desc(build, testcase, test_name):
            test_link = build_uri('/projects/{0}/builds/{1}/jobs/{2}/tests/{3}/'.format(
                build.project.slug,
                build.id.hex,
                testcase.job_id.hex,
                testcase.id.hex
            ))
            return "[%s](%s)" % (test_name, test_link)
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='Server', slug='project-slug')
        self.assertEquals(phab.call_count, 0)
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project, result=Result.failed, target='D1', source=source, status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.failed,
            )
        testcase2 = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo2',
            job=job,
            duration=134,
            result=Result.failed,
            )
        get_base_failures.return_value = {testcase.name}

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build.project.slug, build.id.hex))
        failure_link = build_uri('/projects/{0}/builds/{1}/tests/?result=failed'.format(
            build.project.slug, build.id.hex))

        test_desc = get_test_desc(build, testcase, 'test_foo')
        test_desc2 = get_test_desc(build, testcase2, 'test_foo2')
        expected_msg = """Server build Failed {{icon times, color=red}} ([results]({0})). There were 1 new [test failures]({1})

**New failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|

**Failures in parent revision (1):**
|Test Name | Package|
|--|--|
|{3}|test.group.ClassName|"""

        phab.assert_called_once_with('1', expected_msg.format(build_link, failure_link, test_desc2, test_desc))
Exemplo n.º 13
0
 def test_arc_test_build(self, get_options, post):
     get_options.return_value = {
         'phabricator.notify': '1'
     }
     project = self.create_project(name='test', slug='project-slug')
     self.assertEquals(post.call_count, 0)
     build = self.create_build(project, result=Result.failed, target='D1', status=Status.finished,
             tags=['arc test'])
     build_finished_handler(build_id=build.id.hex)
     self.assertEquals(post.call_count, 0)
Exemplo n.º 14
0
 def test_arc_test_build(self, get_options, post):
     get_options.return_value = {'phabricator.notify': '1'}
     project = self.create_project(name='test', slug='project-slug')
     self.assertEquals(post.call_count, 0)
     build = self.create_build(project,
                               result=Result.failed,
                               target='D1',
                               status=Status.finished,
                               tags=['arc test'])
     build_finished_handler(build_id=build.id.hex)
     self.assertEquals(post.call_count, 0)
Exemplo n.º 15
0
    def test_whitelisted_project(self, get_options, phab):
        get_options.return_value = {"phabricator.notify": "1"}
        project = self.create_project(name="test", slug="project-slug")
        self.assertEquals(phab.call_count, 0)
        build = self.create_build(project, result=Result.failed, target="D1", status=Status.finished)
        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri("/projects/{0}/builds/{1}/".format(build.project.slug, build.id.hex))
        expected_msg = "test build Failed {{icon times, color=red}} ([results]({0})).".format(build_link)

        phab.assert_called_once_with("1", expected_msg)
Exemplo n.º 16
0
    def test_whitelisted_project(self, get_options, phab):
        get_options.return_value = {'phabricator.notify': '1'}
        project = self.create_project(name='test', slug='project-slug')
        self.assertEquals(phab.call_count, 0)
        build = self.create_build(project, result=Result.failed, target='D1')
        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build.project.slug, build.id.hex))
        expected_msg = "Build Failed - test #1 (D1). Build Results: [link]({0})".format(
            build_link)

        phab.assert_called_once_with('1', expected_msg)
Exemplo n.º 17
0
    def test_max_shown_build_failures(self, get_options, phab):
        get_options.return_value = {'phabricator.notify': '1'}
        project = self.create_project(name='Server', slug='project-slug')
        self.assertEquals(phab.call_count, 0)
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project,
                                  result=Result.failed,
                                  target='D1',
                                  source=source,
                                  status=Status.finished)
        job = self.create_job(build=build)
        max_shown = current_app.config.get(
            'MAX_SHOWN_ITEMS_PER_BUILD_PHABRICATOR', 10)
        total_test_count = max_shown + 1
        testcases = []
        for i in range(total_test_count):
            testcases.append(
                self.create_test(
                    package='test.group.ClassName',
                    name='test.group.ClassName.test_foo{}'.format(i),
                    job=job,
                    duration=134,
                    result=Result.failed,
                ))

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build.project.slug, build.id.hex))
        failure_link = build_uri(
            '/projects/{0}/builds/{1}/tests/?result=failed'.format(
                build.project.slug, build.id.hex))

        assert phab.call_count == 1
        (diff_id, comment), _ = phab.call_args
        assert diff_id == '1'
        shown_test_count = 0
        for testcase in testcases:
            test_link = build_uri(
                '/projects/{0}/builds/{1}/jobs/{2}/tests/{3}/'.format(
                    build.project.slug, build.id.hex, testcase.job_id.hex,
                    testcase.id.hex))
            if test_link in comment:
                shown_test_count += 1
        assert shown_test_count == max_shown
        assert 'Server build Failed {{icon times, color=red}} ([results]({0})). There were {2} new [test failures]({1})'.format(
            build_link, failure_link, total_test_count)
        assert '|...more...|...|' in comment
Exemplo n.º 18
0
    def test_build_failure_with_tests(self, get_options, post):
        get_options.return_value = {'phabricator.notify': '1'}
        project = self.create_project(name='Server', slug='project-slug')
        base_source = self.create_source(project, revision_sha='1235')
        base_build = self.create_build(project,
                                       result=Result.passed,
                                       source=base_source,
                                       status=Status.finished)
        self.create_job(build=base_build)
        self.assertEquals(post.call_count, 0)

        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project,
                                  result=Result.failed,
                                  target='D1',
                                  source=source,
                                  status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.failed,
        )

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_web_uri('/find_build/{0}/'.format(build.id.hex))
        failure_link = build_web_uri('/build_tests/{0}/'.format(build.id.hex))

        test_link = build_web_uri('/build_test/{0}/{1}/'.format(
            build.id.hex,
            testcase.id.hex,
        ))
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """(IMPORTANT) Failing builds!\n\n - [Server]({0}). There were 1 new [test failures]({1})

**New failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|"""

        post.assert_called_once_with(
            '1', expected_msg.format(build_link, failure_link, test_desc),
            mock.ANY)
Exemplo n.º 19
0
    def test_whitelisted_project(self, get_options, post):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='test', slug='project-slug')
        self.assertEquals(post.call_count, 0)
        build = self.create_build(project, result=Result.failed, target='D1', status=Status.finished)
        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/find_build/{0}/'.format(build.id.hex))
        expected_msg = "test build Failed {{icon times, color=red}} ([results]({0})).".format(
            build_link
        )

        post.assert_called_once_with('1', expected_msg, mock.ANY)
Exemplo n.º 20
0
    def test_whitelisted_project(self, get_options, phab):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='test', slug='project-slug')
        self.assertEquals(phab.call_count, 0)
        build = self.create_build(project, result=Result.failed, target='D1')
        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build.project.slug, build.id.hex))
        expected_msg = "Build Failed - test #1 (D1). Build Results: [link]({0})".format(
            build_link)

        phab.assert_called_once_with('1', expected_msg)
Exemplo n.º 21
0
    def test_whitelisted_project(self, get_options, post):
        get_options.return_value = {'phabricator.notify': '1'}
        project = self.create_project(name='test', slug='project-slug')
        self.assertEquals(post.call_count, 0)
        build = self.create_build(project,
                                  result=Result.failed,
                                  target='D1',
                                  status=Status.finished)
        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/find_build/{0}/'.format(build.id.hex))
        expected_msg = "test build Failed {{icon times, color=red}} ([results]({0})).".format(
            build_link)

        post.assert_called_once_with('1', expected_msg, mock.ANY)
Exemplo n.º 22
0
    def test_build_failure_with_tests_and_no_base_job(self, get_options, post):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='Server', slug='project-slug')
        base_source = self.create_source(project, revision_sha='1235')
        base_build = self.create_build(project, result=Result.passed,
                                       source=base_source,
                                       status=Status.finished)
        self.assertEquals(post.call_count, 0)

        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project, result=Result.failed, target='D1',
                                  source=source, status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.failed,
            )

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build.project.slug, build.id.hex))
        failure_link = build_uri('/projects/{0}/builds/{1}/tests/?result=failed'.format(
            build.project.slug, build.id.hex))

        test_link = build_uri('/projects/{0}/builds/{1}/jobs/{2}/tests/{3}/'.format(
            build.project.slug,
            build.id.hex,
            testcase.job_id.hex,
            testcase.id.hex
        ))
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """Server build Failed {{icon times, color=red}} ([results]({0})). There were a total of 1 [test failures]({1}), but we could not determine if any of these tests were previously failing.

**All failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|"""

        post.assert_called_once_with('1', expected_msg.format(build_link, failure_link, test_desc), mock.ANY)
Exemplo n.º 23
0
    def test_build_failure_with_tests_and_no_base_job(self, get_options, post):
        get_options.return_value = {'phabricator.notify': '1'}
        project = self.create_project(name='Server', slug='project-slug')
        base_source = self.create_source(project, revision_sha='1235')
        base_build = self.create_build(project,
                                       result=Result.passed,
                                       source=base_source,
                                       status=Status.finished)
        self.assertEquals(post.call_count, 0)

        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project,
                                  result=Result.failed,
                                  target='D1',
                                  source=source,
                                  status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.failed,
        )

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/find_build/{0}/'.format(build.id.hex))
        failure_link = build_uri('/build_tests/{0}/'.format(build.id.hex))

        test_link = build_uri('/build_test/{0}/{1}/'.format(
            build.id.hex,
            testcase.id.hex,
        ))
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """Server build Failed {{icon times, color=red}} ([results]({0})). There were a total of 1 [test failures]({1}), but we could not determine if any of these tests were previously failing.

**All failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|"""

        post.assert_called_once_with(
            '1', expected_msg.format(build_link, failure_link, test_desc),
            mock.ANY)
Exemplo n.º 24
0
    def test_build_failure_with_tests(self, get_options, phab):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='Server', slug='project-slug')
        base_source = self.create_source(project, revision_sha='1235')
        base_build = self.create_build(project, result=Result.passed, source=base_source,
                                       status=Status.finished)
        self.create_job(build=base_build)
        self.assertEquals(phab.call_count, 0)

        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project, result=Result.failed, target='D1', source=source, status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.failed,
            )

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build.project.slug, build.id.hex))
        failure_link = build_uri('/projects/{0}/builds/{1}/tests/?result=failed'.format(
            build.project.slug, build.id.hex))

        test_link = build_uri('/projects/{0}/builds/{1}/jobs/{2}/tests/{3}/'.format(
            build.project.slug,
            build.id.hex,
            testcase.job_id.hex,
            testcase.id.hex
        ))
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """Server build Failed {{icon times, color=red}} ([results]({0})). There were 1 new [test failures]({1})

**New failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|"""

        phab.assert_called_once_with('1', expected_msg.format(build_link, failure_link, test_desc))
Exemplo n.º 25
0
    def test_max_shown_build_failures(self, get_options, phab):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='Server', slug='project-slug')
        self.assertEquals(phab.call_count, 0)
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project, result=Result.failed, target='D1', source=source, status=Status.finished)
        job = self.create_job(build=build)
        max_shown = current_app.config.get('MAX_SHOWN_ITEMS_PER_BUILD_PHABRICATOR', 10)
        total_test_count = max_shown + 1
        testcases = []
        for i in range(total_test_count):
            testcases.append(self.create_test(
                package='test.group.ClassName',
                name='test.group.ClassName.test_foo{}'.format(i),
                job=job,
                duration=134,
                result=Result.failed,
                ))

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/projects/{0}/builds/{1}/'.format(
            build.project.slug, build.id.hex))
        failure_link = build_uri('/projects/{0}/builds/{1}/tests/?result=failed'.format(
            build.project.slug, build.id.hex))

        assert phab.call_count == 1
        (diff_id, comment), _ = phab.call_args
        assert diff_id == '1'
        shown_test_count = 0
        for testcase in testcases:
            test_link = build_uri('/projects/{0}/builds/{1}/jobs/{2}/tests/{3}/'.format(
                build.project.slug,
                build.id.hex,
                testcase.job_id.hex,
                testcase.id.hex
            ))
            if test_link in comment:
                shown_test_count += 1
        assert shown_test_count == max_shown
        assert 'Server build Failed {{icon times, color=red}} ([results]({0})). There were {2} new [test failures]({1})'.format(build_link, failure_link, total_test_count)
        assert '|...more...|...|' in comment
Exemplo n.º 26
0
    def test_no_coverage_posted(self, get_options, merged_coverage_data,
                             post_diff_coverage, post_diff_comment):
        get_options.return_value = {
            'phabricator.notify': '1',
            'phabricator.coverage': '0',  # With this off, no coverage should be posted
        }
        project = self.create_project(name='Server', slug='project-slug')
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project, result=Result.passed, target='D1', source=source, status=Status.finished)
        job = self.create_job(build=build)

        cov = {"file": "NUC"}
        merged_coverage_data.return_value = cov

        build_finished_handler(build_id=build.id.hex)

        assert post_diff_comment.call_count == 1
        assert post_diff_coverage.call_count == 0
Exemplo n.º 27
0
    def test_build_failure_with_tests(self, get_options, post):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='Server', slug='project-slug')
        base_source = self.create_source(project, revision_sha='1235')
        base_build = self.create_build(project, result=Result.passed, source=base_source,
                                       status=Status.finished)
        self.create_job(build=base_build)
        self.assertEquals(post.call_count, 0)

        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project, result=Result.failed, target='D1', source=source, status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.failed,
            )

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_web_uri('/find_build/{0}/'.format(build.id.hex))
        failure_link = build_web_uri('/build_tests/{0}/'.format(build.id.hex))

        test_link = build_web_uri('/build_test/{0}/{1}/'.format(
            build.id.hex,
            testcase.id.hex,
        ))
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """(IMPORTANT) Failing builds!\n\n - [Server]({0}). There were 1 new [test failures]({1})

**New failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|"""

        post.assert_called_once_with('1', expected_msg.format(build_link, failure_link, test_desc), mock.ANY)
Exemplo n.º 28
0
    def test_nonnotifying_build(self, post):
        project1 = self.create_project(name='project1', slug='project1', notify='0')
        project2 = self.create_project(name='project2', slug='project2')
        collection_id = uuid.uuid4()
        build1 = self.create_build(project1, target='D1', collection_id=collection_id, result=Result.failed, status=Status.finished)
        build2 = self.create_build(project2, target='D1', collection_id=collection_id, result=Result.unknown, status=Status.in_progress)

        build_finished_handler(build_id=build1.id.hex)
        assert post.call_count == 0

        build2.result = Result.failed
        build2.status = Status.finished
        db.session.add(build2)
        db.session.commit()

        build_finished_handler(build_id=build2.id.hex)
        assert post.call_count == 1

        args, kwargs = post.call_args
        id, msg, request = args
        assert 'project1' not in msg
        assert 'project2' in msg
Exemplo n.º 29
0
    def test_no_new_failures(self, get_options, phab, get_base_failures):
        get_options.return_value = {"phabricator.notify": "1"}
        project = self.create_project(name="Server", slug="project-slug")
        self.assertEquals(phab.call_count, 0)
        patch = self.create_patch()
        source = self.create_source(project, revision_sha="1235", patch=patch)
        build = self.create_build(project, result=Result.failed, target="D1", source=source, status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package="test.group.ClassName",
            name="test.group.ClassName.test_foo",
            job=job,
            duration=134,
            result=Result.failed,
        )
        get_base_failures.return_value = {testcase.name}

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri("/projects/{0}/builds/{1}/".format(build.project.slug, build.id.hex))
        failure_link = build_uri(
            "/projects/{0}/builds/{1}/tests/?result=failed".format(build.project.slug, build.id.hex)
        )

        test_link = build_uri(
            "/projects/{0}/builds/{1}/jobs/{2}/tests/{3}/".format(
                build.project.slug, build.id.hex, testcase.job_id.hex, testcase.id.hex
            )
        )
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """Server build Failed {{icon times, color=red}} ([results]({0})). There were 0 new [test failures]({1})

**Failures in parent revision (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|"""

        phab.assert_called_once_with("1", expected_msg.format(build_link, failure_link, test_desc))
Exemplo n.º 30
0
    def test_no_new_failures(self, get_options, post, get_base_failures):
        get_options.return_value = {
            'phabricator.notify': '1'
        }
        project = self.create_project(name='Server', slug='project-slug')
        self.assertEquals(post.call_count, 0)
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project, result=Result.failed, target='D1', source=source, status=Status.finished)
        job = self.create_job(build=build)
        testcase = self.create_test(
            package='test.group.ClassName',
            name='test.group.ClassName.test_foo',
            job=job,
            duration=134,
            result=Result.failed,
            )
        get_base_failures.return_value = {testcase.name}

        build_finished_handler(build_id=build.id.hex)

        get_options.assert_called_once_with(project.id)
        build_link = build_uri('/find_build/{0}/'.format(build.id.hex))
        failure_link = build_uri('/build_tests/{0}/'.format(build.id.hex))

        test_link = build_uri('/build_test/{0}/{1}/'.format(
            build.id.hex,
            testcase.id.hex,
        ))
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """Server build Failed {{icon times, color=red}} ([results]({0})). There were 0 new [test failures]({1})

**Failures in parent revision (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|"""

        post.assert_called_once_with('1', expected_msg.format(build_link, failure_link, test_desc), mock.ANY)
Exemplo n.º 31
0
    def test_commit_coverage_posted(self, get_options, merged_coverage_data,
                                    post_diff_coverage, post_commit_coverage,
                                    post_diff_comment):
        get_options.return_value = {
            'phabricator.notify': '1',
            'phabricator.coverage': '1',
        }
        repo = self.create_repo(backend=RepositoryBackend.git)
        self.create_option(name='phabricator.callsign',
                           value='BOO',
                           item_id=repo.id)
        project = self.create_project(name='Server', repository=repo)
        source = self.create_source(project)
        revision_id = 12345
        build = self.create_build(
            project,
            result=Result.passed,
            source=source,
            status=Status.finished,
            tags=['commit'],
            message='commit message\nDifferential Revision: '
            'https://phabricator.example.com/D{}'.format(revision_id))
        job = self.create_job(build=build)

        cov = {"file": "NUC"}
        merged_coverage_data.return_value = cov

        build_finished_handler(build_id=build.id.hex)

        assert post_diff_comment.call_count == 0
        assert post_diff_coverage.call_count == 1
        post_diff_coverage.assert_called_once_with(revision_id, cov, mock.ANY)
        assert post_commit_coverage.call_count == 1
        post_commit_coverage.assert_called_once_with('BOO', 'master',
                                                     source.revision_sha, cov,
                                                     mock.ANY)
Exemplo n.º 32
0
    def test_no_coverage_posted(self, get_options, merged_coverage_data,
                                post_diff_coverage, post_diff_comment):
        get_options.return_value = {
            'phabricator.notify': '1',
            'phabricator.coverage':
            '0',  # With this off, no coverage should be posted
        }
        project = self.create_project(name='Server', slug='project-slug')
        patch = self.create_patch()
        source = self.create_source(project, revision_sha='1235', patch=patch)
        build = self.create_build(project,
                                  result=Result.passed,
                                  target='D1',
                                  source=source,
                                  status=Status.finished)
        job = self.create_job(build=build)

        cov = {"file": "NUC"}
        merged_coverage_data.return_value = cov

        build_finished_handler(build_id=build.id.hex)

        assert post_diff_comment.call_count == 1
        assert post_diff_coverage.call_count == 0
Exemplo n.º 33
0
    def test_multiple_builds(self, get_options, post):
        get_options.return_value = {'phabricator.notify': '1'}
        project1 = self.create_project(name='Server', slug='project-slug')
        project2 = self.create_project(name='Server2', slug='project-slug2')
        self.assertEquals(post.call_count, 0)
        collection_id = uuid.uuid4()

        def create_build(result, project):
            base_source = self.create_source(project, revision_sha='1235')
            base_build = self.create_build(project,
                                           result=Result.passed,
                                           source=base_source,
                                           status=Status.finished)
            self.create_job(build=base_build)

            patch = self.create_patch()
            source = self.create_source(project,
                                        revision_sha='1235',
                                        patch=patch)
            build = self.create_build(project,
                                      result=result,
                                      target='D1',
                                      source=source,
                                      status=Status.finished,
                                      collection_id=collection_id)
            job = self.create_job(build=build)
            testcase = self.create_test(
                package='test.group.ClassName',
                name='test.group.ClassName.test_foo',
                job=job,
                duration=134,
                result=result,
            )
            return build, testcase

        build1, testcase1 = create_build(Result.failed, project1)
        build2, testcase2 = create_build(Result.passed, project2)

        build_finished_handler(build_id=build1.id.hex)

        build_link = build_web_uri('/find_build/{0}/'.format(build1.id.hex))
        build2_link = build_web_uri('/find_build/{0}/'.format(build2.id.hex))
        failure_link = build_web_uri('/build_tests/{0}/'.format(build1.id.hex))

        test_link = build_web_uri('/build_test/{0}/{1}/'.format(
            build1.id.hex,
            testcase1.id.hex,
        ))
        test_desc = "[test_foo](%s)" % test_link
        expected_msg = """(IMPORTANT) Failing builds!\n\n - [Server]({0}). There were 1 new [test failures]({1})

**New failures (1):**
|Test Name | Package|
|--|--|
|{2}|test.group.ClassName|

(NOTE) Passing builds:

 - [Server2]({3})."""

        post.assert_called_once_with(
            '1',
            expected_msg.format(build_link, failure_link, test_desc,
                                build2_link), mock.ANY)
Exemplo n.º 34
0
 def test_no_target(self, get_options, phab):
     project = self.create_project(name='test', slug='test')
     build = self.create_build(project, result=Result.failed, status=Status.finished)
     build_finished_handler(build_id=build.id.hex)
     self.assertEquals(phab.call_count, 0)