예제 #1
0
def test_record_job_result(session, fixtures):

    library_master = "lib-master-sha"

    # test app@sha1 against master library
    record_job_sha('app_integration', 1, 'owner', 'app', 'sha1')
    record_job_sha('app_integration', 1, 'owner', 'library', library_master)

    record_job_result('app_integration', 1, True, "passed")

    assert session.query(BuildSha).count() == 2
    assert session.query(BuildSha).filter_by(
        sha=library_master).one().project.name == "library"
    assert session.query(BuildSha).filter_by(
        sha="sha1").one().project.name == "app"

    # test app@sha2 against master library
    record_job_sha('app_integration', 2, 'owner', 'app', 'sha2')
    record_job_sha('app_integration', 2, 'owner', 'library', library_master)

    record_job_result('app_integration', 2, True, "passed")

    assert session.query(BuildSha).count() == 4
    assert session.query(BuildSha).filter_by(
        sha="sha2").one().project.name == "app"
예제 #2
0
def test_get_prs_for_build(session, fixtures):

    set_master(session, 'app', 'sha1')
    set_master(session, 'library', 'sha2')

    app_pr = make_pr(session, project_name='app', sha='1234')

    with patch('cinch.jenkins.controllers.dispatcher') as dispatcher:
        with dispatcher() as dispatch:
            pass

        record_job_sha('app_integration', 1, 'owner', 'library', 'sha2')
        assert dispatch.call_count == 0

        record_job_sha('app_integration', 1, 'owner', 'app', '1234')
        assert dispatch.call_count == 1

        record_job_result('app_integration', 1, True, "passed")
        assert dispatch.call_count == 2

    job = session.query(Job).filter(Job.name == 'app_integration').one()
    build = get_or_create_build(job, 1)
    prs = get_prs_for_build(build).all()

    assert len(prs) == 1
    assert prs[0] == app_pr
예제 #3
0
def test_multiple_prs_for_build(session, fixtures):

    set_master(session, 'app', 'sha1')
    set_master(session, 'library', 'sha2')

    app_pr = make_pr(session, project_name='app', sha='1234')
    library_pr = make_pr(session, project_name='library', sha='2345')

    with patch('cinch.jenkins.controllers.dispatcher') as dispatcher:
        with dispatcher() as dispatch:
            pass

        record_job_sha('app_integration', 1, 'owner', 'app', '1234')
        assert dispatch.call_count == 1

        record_job_sha('app_integration', 1, 'owner', 'library', '2345')
        # both pull requests will be recorded from this point
        assert dispatch.call_count == 3

        record_job_result('app_integration', 1, True, "passed")
        assert dispatch.call_count == 5

    job = session.query(Job).filter(Job.name == 'app_integration').one()
    build = get_or_create_build(job, 1)
    prs = get_prs_for_build(build).all()

    assert len(prs) == 2
    assert app_pr in prs
    assert library_pr in prs
예제 #4
0
def test_get_prs_for_build(session, fixtures):

    set_master(session, 'app', 'sha1')
    set_master(session, 'library', 'sha2')

    app_pr = make_pr(session, project_name='app', sha='1234')

    with patch('cinch.jenkins.controllers.dispatcher') as dispatcher:
        with dispatcher() as dispatch:
            pass

        record_job_sha('app_integration', 1, 'owner', 'library', 'sha2')
        assert dispatch.call_count == 0

        record_job_sha('app_integration', 1, 'owner', 'app', '1234')
        assert dispatch.call_count == 1

        record_job_result('app_integration', 1, True, "passed")
        assert dispatch.call_count == 2

    job = session.query(Job).filter(Job.name == 'app_integration').one()
    build = get_or_create_build(job, 1)
    prs = get_prs_for_build(build).all()

    assert len(prs) == 1
    assert prs[0] == app_pr
예제 #5
0
def test_statuses(session, fixtures, app_context):
    library = fixtures['library']
    lib_sha = "lib-proposed-sha"

    pull_request = PullRequest(
        is_open=True,
        number=1,
        project=library,
        head=lib_sha,
        owner='',
        title='',
    )
    db.session.add(pull_request)
    db.session.commit()

    # unknown
    assert job_status(app_context, pull_request, 'library_unit') is None

    record_job_sha('library_unit', 1, 'owner', 'library', lib_sha)
    # still unknown
    assert job_status(app_context, pull_request, 'library_unit') is None

    # succeeded
    record_job_result('library_unit', 1, True, "")
    assert job_status(app_context, pull_request, 'library_unit') is True

    # failed
    record_job_result('library_unit', 1, False, "")
    assert job_status(app_context, pull_request, 'library_unit') is False
예제 #6
0
def test_record_job_result(session, fixtures):

    library_master = "lib-master-sha"

    # test app@sha1 against master library
    record_job_sha('app_integration', 1, 'owner', 'app', 'sha1')
    record_job_sha('app_integration', 1, 'owner', 'library', library_master)

    record_job_result('app_integration', 1, True, "passed")

    assert session.query(BuildSha).count() == 2
    assert session.query(BuildSha).filter_by(
        sha=library_master).one().project.name == "library"
    assert session.query(BuildSha).filter_by(
        sha="sha1").one().project.name == "app"

    # test app@sha2 against master library
    record_job_sha('app_integration', 2, 'owner', 'app', 'sha2')
    record_job_sha('app_integration', 2, 'owner', 'library', library_master)

    record_job_result('app_integration', 2, True, "passed")

    assert session.query(BuildSha).count() == 4
    assert session.query(BuildSha).filter_by(
        sha="sha2").one().project.name == "app"
예제 #7
0
def test_multiple_prs_for_build(session, fixtures):

    set_master(session, 'app', 'sha1')
    set_master(session, 'library', 'sha2')

    app_pr = make_pr(session, project_name='app', sha='1234')
    library_pr = make_pr(session, project_name='library', sha='2345')

    with patch('cinch.jenkins.controllers.dispatcher') as dispatcher:
        with dispatcher() as dispatch:
            pass

        record_job_sha('app_integration', 1, 'owner', 'app', '1234')
        assert dispatch.call_count == 1

        record_job_sha('app_integration', 1, 'owner', 'library', '2345')
        # both pull requests will be recorded from this point
        assert dispatch.call_count == 3

        record_job_result('app_integration', 1, True, "passed")
        assert dispatch.call_count == 5

    job = session.query(Job).filter(Job.name == 'app_integration').one()
    build = get_or_create_build(job, 1)
    prs = get_prs_for_build(build).all()

    assert len(prs) == 2
    assert app_pr in prs
    assert library_pr in prs
예제 #8
0
def test_dont_match_if_merge_head_is_none(session, fixtures, app_context):
    # no shas recorded
    record_job_result('library_unit', 1, True, "passed")

    clear_g_cache()
    pr = make_pr(session, 'library', 'sha')
    pr.merge_head = None

    assert jenkins_check(pr).status is None
예제 #9
0
def test_dont_match_if_merge_head_is_none(session, fixtures, app_context):
    # no shas recorded
    record_job_result('library_unit', 1, True, "passed")

    clear_g_cache()
    pr = make_pr(session, 'library', 'sha')
    pr.merge_head = None

    assert jenkins_check(pr).status is None
예제 #10
0
    def test_multi_project_job(self, fixtures):
        library = fixtures['library']
        app = fixtures['app']

        # app@sha2 integration passes against library@sha3
        shas = OrderedDict([
            (app.id, ''),
            (library.id, ''),
        ])
        record_job_sha('app_integration', 2, 'owner', 'app', 'sha2')
        record_job_sha('app_integration', 2, 'owner', 'library', 'sha3')
        record_job_result('app_integration', 2, True, "passed")

        successful = get_shas(fixtures['app_integration'].id, shas)
        assert successful[('sha2', 'sha3')] == (2, True)
예제 #11
0
    def test_multi_project_job(self, fixtures):
        library = fixtures['library']
        app = fixtures['app']

        # app@sha2 integration passes against library@sha3
        shas = OrderedDict([
            (app.id, ''),
            (library.id, ''),
        ])
        record_job_sha('app_integration', 2, 'owner', 'app', 'sha2')
        record_job_sha('app_integration', 2, 'owner', 'library', 'sha3')
        record_job_result('app_integration', 2, True, "passed")

        successful = get_shas(fixtures['app_integration'].id, shas)
        assert successful[('sha2', 'sha3')] == (2, True)
예제 #12
0
def test_multiple_builds_for_same_job_and_sha(session, app_context):
    project = Project(name='project', owner='owner')
    job = Job(name='job', projects=[project])
    session.add(job)
    session.commit()

    sha = "proposed-sha"

    record_job_sha('job', 1, 'owner', 'project', sha)
    record_job_sha('job', 2, 'owner', 'project', sha)

    record_job_result('job', 1, True, "passed")
    record_job_result('job', 2, False, "passed")

    assert build_check(session, 'project', sha)
예제 #13
0
    def test_one_query_per_job(self, session, fixtures):
        n_queries = [0]
        foo = []

        @event.listens_for(Engine, "after_cursor_execute")
        def after_cursor_execute(*args, **kwargs):
            foo.append((args, kwargs))
            n_queries[0] += 1

        for x in range(20):
            record_job_sha('app_integration', x, 'owner', 'app',
                           'shax{}'.format(x))
            record_job_sha('app_integration', x, 'owner', 'library',
                           'shay{}'.format(x))
            record_job_result('app_integration', x, True, "passed")

        library = fixtures['library']
        app = fixtures['app']

        app_integration_id = fixtures['app_integration'].id
        app_unit_id = fixtures['app_unit'].id
        shas = OrderedDict([
            (app.id, ''),
            (library.id, ''),
        ])

        # single job
        with QueryCounter() as qc:
            get_job_sha_statuses({app_integration_id: shas})
        assert qc.count == 1

        # 2 jobs
        with QueryCounter() as qc:
            get_job_sha_statuses({
                app_integration_id: shas,
                app_unit_id: shas,
            })
        assert qc.count == 2

        # jobs with no projects
        with QueryCounter() as qc:
            get_job_sha_statuses({
                app_integration_id: {},
                app_unit_id: {},
            })
        assert qc.count == 2
예제 #14
0
    def test_single_project_job(self, fixtures):
        library = fixtures['library']

        # library@sha1 passes unit tests
        record_job_sha('library_unit', 1, 'owner', 'library', 'sha1')
        record_job_result('library_unit', 1, True, "passed")

        shas = OrderedDict([
            (library.id, 'sha1'),
        ])
        successful = get_shas(
            fixtures['library_unit'].id,
            shas,
        )
        assert successful == {
            ('sha1',): (1, True),
        }
예제 #15
0
    def test_single_project_job(self, fixtures):
        library = fixtures['library']

        # library@sha1 passes unit tests
        record_job_sha('library_unit', 1, 'owner', 'library', 'sha1')
        record_job_result('library_unit', 1, True, "passed")

        shas = OrderedDict([
            (library.id, 'sha1'),
        ])
        successful = get_shas(
            fixtures['library_unit'].id,
            shas,
        )
        assert successful == {
            ('sha1', ): (1, True),
        }
예제 #16
0
    def test_one_query_per_job(self, session, fixtures):
        n_queries = [0]
        foo = []

        @event.listens_for(Engine, "after_cursor_execute")
        def after_cursor_execute(*args, **kwargs):
            foo.append((args, kwargs))
            n_queries[0] += 1

        for x in range(20):
            record_job_sha(
                'app_integration', x, 'owner', 'app', 'shax{}'.format(x))
            record_job_sha(
                'app_integration', x, 'owner', 'library', 'shay{}'.format(x))
            record_job_result('app_integration', x, True, "passed")

        library = fixtures['library']
        app = fixtures['app']

        app_integration_id = fixtures['app_integration'].id
        app_unit_id = fixtures['app_unit'].id
        shas = OrderedDict([
            (app.id, ''),
            (library.id, ''),
        ])

        # single job
        with QueryCounter() as qc:
            get_job_sha_statuses({app_integration_id: shas})
        assert qc.count == 1

        # 2 jobs
        with QueryCounter() as qc:
            get_job_sha_statuses({
                app_integration_id: shas,
                app_unit_id: shas,
            })
        assert qc.count == 2

        # jobs with no projects
        with QueryCounter() as qc:
            get_job_sha_statuses({
                app_integration_id: {},
                app_unit_id: {},
            })
        assert qc.count == 2
예제 #17
0
    def test_unsuccesful_builds(self, fixtures):
        library = fixtures['library']
        app = fixtures['app']

        shas = OrderedDict([
            (app.id, ''),
            (library.id, ''),
        ])
        record_job_sha('app_integration', 2, 'owner', 'app', 'sha2')
        record_job_sha('app_integration', 2, 'owner', 'library', 'sha3')
        record_job_result('app_integration', 2, True, "passed")

        record_job_sha('app_integration', 4, 'owner', 'app', 'sha4')
        record_job_sha('app_integration', 4, 'owner', 'library', 'sha5')
        record_job_result('app_integration', 4, False, "passed")

        sha_statuses = get_shas(fixtures['app_integration'].id, shas)
        assert sha_statuses == {
            ('sha2', 'sha3'): (2, True),
            ('sha4', 'sha5'): (4, False),
        }
예제 #18
0
    def test_unsuccesful_builds(self, fixtures):
        library = fixtures['library']
        app = fixtures['app']

        shas = OrderedDict([
            (app.id, ''),
            (library.id, ''),
        ])
        record_job_sha('app_integration', 2, 'owner', 'app', 'sha2')
        record_job_sha('app_integration', 2, 'owner', 'library', 'sha3')
        record_job_result('app_integration', 2, True, "passed")

        record_job_sha('app_integration', 4, 'owner', 'app', 'sha4')
        record_job_sha('app_integration', 4, 'owner', 'library', 'sha5')
        record_job_result('app_integration', 4, False, "passed")

        sha_statuses = get_shas(fixtures['app_integration'].id, shas)
        assert sha_statuses == {
            ('sha2', 'sha3'): (2, True),
            ('sha4', 'sha5'): (4, False),
        }
예제 #19
0
    def test_other_job_ignored(self, fixtures):
        library = fixtures['library']
        app = fixtures['app']

        # library@sha1 passes unit tests
        record_job_sha('library_unit', 1, 'owner', 'library', 'sha1')
        record_job_result('library_unit', 1, True, "passed")

        library_unit = fixtures['library_unit']
        app_unit = fixtures['app_unit']
        successful_job_shas = get_job_sha_statuses({
            library_unit.id: {
                library.id: '',
            },
            app_unit.id: {
                app.id: '',
            },
        })
        assert successful_job_shas[library_unit.id] == {
            ('sha1', ): (1, True),
        }
        assert successful_job_shas[app_unit.id] == {}
예제 #20
0
    def test_other_job_ignored(self, fixtures):
        library = fixtures['library']
        app = fixtures['app']

        # library@sha1 passes unit tests
        record_job_sha('library_unit', 1, 'owner', 'library', 'sha1')
        record_job_result('library_unit', 1, True, "passed")

        library_unit = fixtures['library_unit']
        app_unit = fixtures['app_unit']
        successful_job_shas = get_job_sha_statuses({
            library_unit.id: {
                library.id: '',
            },
            app_unit.id: {
                app.id: '',
            },
        })
        assert successful_job_shas[library_unit.id] == {
            ('sha1',): (1, True),
        }
        assert successful_job_shas[app_unit.id] == {}
예제 #21
0
def test_record_job_result(session, fixtures):

    library_master = "lib-master-sha"

    # test small_app@sha1 against master library
    record_job_sha('small_app_integration', 1, 'small_app', 'sha1')
    record_job_sha('small_app_integration', 1, 'library', library_master)

    record_job_result('small_app_integration', 1, True, "passed")

    assert session.query(Commit).count() == 2
    assert session.query(Commit).get(library_master).project.name == "library"
    assert session.query(Commit).get("sha1").project.name == "small_app"

    # test large_app@sha2 against master library
    record_job_sha('large_app_integration', 1, 'large_app', 'sha2')
    record_job_sha('large_app_integration', 1, 'library', library_master)

    record_job_result('large_app_integration', 1, True, "passed")

    assert session.query(Commit).count() == 3
    assert session.query(Commit).get("sha2").project.name == "large_app"
예제 #22
0
def test_integration_test_check(session, fixtures, app_context):
    lib_sha = "lib-proposed-sha"

    # library@proposed-sha passes unit tests
    record_job_sha('library_unit', 1, 'owner', 'library', lib_sha)
    record_job_result('library_unit', 1, True, "passed")

    app = fixtures['app']

    # set project master_shas
    app.master_sha = "sha1"
    session.commit()

    # library integration not yet satisfied
    assert not build_check(session, 'library', lib_sha)

    # app@sha1 integration passes against library@lib_sha
    record_job_sha('app_integration', 1, 'owner', 'app', 'sha1')
    record_job_sha('app_integration', 1, 'owner', 'library', lib_sha)
    record_job_result('app_integration', 1, True, "passed")

    # library integration now satisfied
    assert build_check(session, 'library', lib_sha)
예제 #23
0
def test_integration_test_check(session, fixtures, app_context):
    lib_sha = "lib-proposed-sha"

    # library@proposed-sha passes unit tests
    record_job_sha('library_unit', 1, 'owner', 'library', lib_sha)
    record_job_result('library_unit', 1, True, "passed")

    app = fixtures['app']

    # set project master_shas
    app.master_sha = "sha1"
    session.commit()

    # library integration not yet satisfied
    assert not build_check(session, 'library', lib_sha)

    # app@sha1 integration passes against library@lib_sha
    record_job_sha('app_integration', 1, 'owner', 'app', 'sha1')
    record_job_sha('app_integration', 1, 'owner', 'library', lib_sha)
    record_job_result('app_integration', 1, True, "passed")

    # library integration now satisfied
    assert build_check(session, 'library', lib_sha)
예제 #24
0
    def test_separate_builds_with_same_number(self, session, fixtures):
        library = fixtures['library']
        app = fixtures['app']

        shas = OrderedDict([
            (app.id, ''),
            (library.id, ''),
        ])

        app_integration = fixtures['app_integration']
        app_integration2 = Job(
            name="app_integration2",
            projects=[app, library])

        session.add(app_integration2)
        session.commit()

        record_job_sha('app_integration', 1, 'owner', 'app', 'sha2')
        record_job_sha('app_integration', 1, 'owner', 'library', 'sha3')
        record_job_result('app_integration', 1, True, "passed")

        record_job_sha('app_integration2', 1, 'owner', 'app', 'sha4')
        record_job_sha('app_integration2', 1, 'owner', 'library', 'sha5')
        record_job_result('app_integration2', 1, True, "passed")

        successful = get_job_sha_statuses({
            app_integration.id: shas,
            app_integration2.id: shas,
        })
        assert successful == {
            app_integration.id: {
                ('sha2', 'sha3'): (1, True),
            },
            app_integration2.id: {
                ('sha4', 'sha5'): (1, True)
            },
        }
예제 #25
0
    def test_separate_builds_with_same_number(self, session, fixtures):
        library = fixtures['library']
        app = fixtures['app']

        shas = OrderedDict([
            (app.id, ''),
            (library.id, ''),
        ])

        app_integration = fixtures['app_integration']
        app_integration2 = Job(name="app_integration2",
                               projects=[app, library])

        session.add(app_integration2)
        session.commit()

        record_job_sha('app_integration', 1, 'owner', 'app', 'sha2')
        record_job_sha('app_integration', 1, 'owner', 'library', 'sha3')
        record_job_result('app_integration', 1, True, "passed")

        record_job_sha('app_integration2', 1, 'owner', 'app', 'sha4')
        record_job_sha('app_integration2', 1, 'owner', 'library', 'sha5')
        record_job_result('app_integration2', 1, True, "passed")

        successful = get_job_sha_statuses({
            app_integration.id: shas,
            app_integration2.id: shas,
        })
        assert successful == {
            app_integration.id: {
                ('sha2', 'sha3'): (1, True),
            },
            app_integration2.id: {
                ('sha4', 'sha5'): (1, True)
            },
        }
예제 #26
0
def test_integration_test_check(session, fixtures, app_context):
    lib_sha = "lib-proposed-sha"

    # library@proposed-sha passes unit tests
    record_job_sha('library_unit', 1, 'library', lib_sha)
    record_job_result('library_unit', 1, True, "passed")


    small_app = fixtures['small_app']
    large_app = fixtures['large_app']
    mobile = fixtures['mobile']

    # set project master_shas
    small_app.master_sha = "sha1"
    large_app.master_sha = "sha2"
    mobile.master_sha = "sha3"
    session.commit()

    # small_app@sha1 integration passes against library@lib_sha
    shas = {
        'small_app': 'sha1',
        'library': lib_sha
    }
    record_job_shas('small_app_integration', 1, shas)
    record_job_result('small_app_integration', 1, True, "passed")

    # library integration not yet satisfied
    assert not build_check('library', lib_sha)

    # large_app@sha2 integration passes against library@lib_sha
    shas = {
        'large_app': 'sha2',
        'library': lib_sha
    }
    record_job_shas('large_app_integration', 1, shas)
    record_job_result('large_app_integration', 1, True, "passed")

    # library integration not yet satisfied
    assert not build_check('library', lib_sha)

    # mobile@sha3 integration FAILS against library@lib_sha and large_app@sha2
    shas = {
        'mobile': 'sha3',
        'large_app': 'sha2',
        'library': lib_sha
    }
    record_job_shas('mobile_integration', 1, shas)
    record_job_result('mobile_integration', 1, False, "aborted")

    # library integration not yet satisfied
    assert not build_check('library', lib_sha)

    # mobile@sha3 integration PASSES against library@lib_sha,
    # but  against large_app@sha4
    shas = {
        'mobile': 'sha3',
        'large_app': 'sha4',
        'library': lib_sha
    }
    record_job_shas('mobile_integration', 2, shas)
    record_job_result('mobile_integration', 2, True, "passed")

    # library integration not yet satisfied
    assert not build_check('library', lib_sha)

    # mobile@sha3 integration PASSES against library@lib_sha AND large_app@sha2
    shas = {
        'mobile': 'sha3',
        'large_app': 'sha2',
        'library': lib_sha
    }
    record_job_shas('mobile_integration', 3, shas)
    record_job_result('mobile_integration', 3, True, "passed")

    # library integration finally satisfied
    assert build_check('library', lib_sha)
예제 #27
0
def test_get_successful_builds(session, fixtures, app_context):
    library_master = "lib-master-sha"

    # library@master passes unit tests
    shas = {
        'library': library_master
    }
    record_job_sha('library_unit', 1, 'library', library_master)
    record_job_result('library_unit', 1, True, "passed")

    build_shas = shas
    assert get_successful_builds('library', build_shas) == [
        "library_unit"
    ]

    # small_app@sha1 integration passes against library@master
    shas = {
        'small_app': 'sha1',
        'library': library_master
    }
    record_job_sha('small_app_integration', 1, 'small_app', 'sha1')
    record_job_sha('small_app_integration', 1, 'library', library_master)
    record_job_result('small_app_integration', 1, True, "passed")

    build_shas = shas
    assert get_successful_builds('small_app', build_shas) == [
        "small_app_integration"
    ]
    assert "small_app_integration" in get_successful_builds(
        'library', build_shas)

    # large_app@sha2 integration passes against library@master
    shas = {
        'large_app': 'sha2',
        'library': library_master
    }
    record_job_sha('large_app_integration', 1, 'large_app', 'sha2')
    record_job_sha('large_app_integration', 1, 'library', library_master)
    record_job_result('large_app_integration', 1, True, "passed")

    build_shas = shas
    # large_app@sha2 has passed integration against library@master
    assert get_successful_builds('large_app', build_shas) == [
        "large_app_integration"
    ]

    build_shas['small_app'] = "sha1"

    # small_app@sha1 has passed integration against library@master
    # large_app@sha2 has passed integration against library@master
    assert "large_app_integration" in get_successful_builds(
        'library', build_shas)
    assert "small_app_integration" in get_successful_builds(
        'library', build_shas)

    # small_app master is at sha1
    small_app = session.query(Project).filter_by(name="small_app").one()
    small_app.master_sha = "sha1"  # not a foreign key, so we can just write this
    session.commit()

    # so we can omit small_app for build_shas dict
    build_shas.pop('small_app')
    assert "large_app_integration" in get_successful_builds(
        'library', build_shas)
    assert "small_app_integration" in get_successful_builds(
        'library', build_shas)