Exemple #1
0
def test_known_pull_request_task(app, owner, repository, session):
    """Task pull_request /pulls/1 that already exists."""
    httpretty.reset()
    cs1 = CommitStatus(repository, "1", "https://github.com/pulls/1", {
        "message": [],
        "files": {}
    })
    cs2 = CommitStatus(repository, "2", "https://github.com/pulls/2", {
        "message": [],
        "files": {}
    })
    session.add(cs1)
    session.add(cs2)
    session.commit()

    bs = BranchStatus(cs2, "test:my-branch", "https://github.com/pulls/1", {
        "commits": [cs1, cs2],
        "files": {}
    })
    session.add(bs)
    session.commit()
    assert_that(bs.is_pending(), equal_to(False))

    httpretty.enable()
    pull_request(bs.id, "https://api.github.com/pulls/1",
                 "http://kwalitee.invenio-software.org/status/2",
                 {"ACCESS_TOKEN": "deadbeef"})
    httpretty.disable()

    latest_requests = httpretty.HTTPretty.latest_requests
    assert_that(len(latest_requests), equal_to(0), "No requests are expected")
def commits(owner, repository, session, request):
    """Create a couple of commits for a test."""
    cs = [
        {"sha": "ef01234"},
        {"sha": "789abcd"},
        {"sha": "0123456"},
    ]
    url_template = "https://github.com/commits/{sha}"

    commits = []
    for commit in cs:
        cs = CommitStatus(repository,
                          commit["sha"],
                          url_template.format(**commit),
                          {"message": [], "files": None})
        commits.append(cs)
        session.add(cs)
    session.commit()

    def teardown():
        for commit in commits:
            session.delete(commit)
        session.commit()

    request.addfinalizer(teardown)
    return commits
Exemple #3
0
def test_push_known_commit(repository, session):
    """Worker push /commits/1 is not rechecked if known"""
    httpretty.reset()
    commit = {
        "sha":
        1,
        "url":
        "https://api.github.com/commits/1",
        "html_url":
        "https://github.com/commits/1",
        "comments_url":
        "https://api.github.com/commits/1/comments",
        "commit": {
            "message": "Fix all the bugs!"
        },
        "files": [{
            "filename": "spam/eggs.py",
            "status": "modified",
            "raw_url": "https://github.com/raw/1/spam/eggs.py"
        }]
    }
    httpretty.register_uri(httpretty.GET,
                           "https://api.github.com/commits/1",
                           body=json.dumps(commit),
                           content_type="application/json")

    cs = CommitStatus(repository, "1", "https://github.com/commits/1", {
        "message": ["error 1", "error 2"],
        "files": {}
    })
    session.add(cs)
    session.commit()
    assert_that(cs.is_pending(), equal_to(False))

    httpretty.enable()
    body = push(cs.id, "https://api.github.com/commits/1",
                "https://api.github.com/statuses/1",
                {"repository": repository.id})
    httpretty.disable()

    latest_requests = httpretty.HTTPretty.latest_requests
    assert_that(len(latest_requests), equal_to(1), "1x GET")

    assert_that(body["description"], contains_string("[error] 2 errors"))
def commit(repository, session, request):
    sha = "060fcc4e4856b1bc7dc0eba0b07d3c734bbf24fd"
    url_template = "https://github.com/invenio/test/commits/{sha}"

    c = CommitStatus(repository,
                     sha,
                     url_template.format(sha=sha),
                     {"message": ["foo", "bar"],
                      "files": {"spam": {"errors": ["spam"]},
                                "eggs": {"errors": ["eggs"]}}})
    session.add(c)
    session.commit()

    def teardown():
        session.delete(c)
        session.commit()

    request.addfinalizer(teardown)
    return c
def branch(owner, repository, session, request):
    cs = [
        {
            "sha": "ef01234"
        },
        {
            "sha": "789abcd"
        },
        {
            "sha": "0123456"
        },
    ]
    name = "spam:wip/my-branch"
    url_template = "https://github.com/invenio/test/commits/{sha}"

    commits = []
    branches = []
    for commit in cs:
        cs = CommitStatus(repository, commit["sha"],
                          url_template.format(**commit))
        commits.append(cs)
        session.add(cs)
        session.commit()

        bs = BranchStatus(commits[-1], name, "http://github.com/pulls/1", {
            "commits": commits,
            "files": {}
        })
        branches.append(bs)
        session.add(bs)
        session.commit()

    def teardown():
        for bs in branches:
            session.delete(bs)
        session.commit()
        for commit in commits:
            session.delete(commit)
        session.commit()

    request.addfinalizer(teardown)
    return branches[-1]
def test_remove(session):
    """remove {account} drops everything tied to it"""
    add("invenio")

    acc = Account.query.filter_by(name="invenio").first()
    rep = Repository.find_or_create(acc, "foo")
    commit = CommitStatus(rep, "1", "http://")
    session.add(commit)
    session.commit()
    bs = BranchStatus(commit, "1", "http://")
    session.add(bs)
    session.commit()

    remove("invenio")

    assert_that(Account.query.filter_by(name="invenio").count(), equal_to(0))
    assert_that(Repository.query.filter_by(name="foo").count(), equal_to(0))
    assert_that(
        CommitStatus.query.filter_by(repository_id=rep.id).count(),
        equal_to(0))
    assert_that(
        BranchStatus.query.filter_by(commit_id=commit.id).count(), equal_to(0))
Exemple #7
0
def test_push_half_known_commit(repository, session):
    """Worker push /commits/1 checks the files if none"""
    httpretty.reset()
    commit = {
        "sha":
        "1",
        "url":
        "https://api.github.com/commits/1",
        "html_url":
        "https://github.com/commits/1",
        "comments_url":
        "https://api.github.com/commits/1/comments",
        "commit": {
            "message": "Fix all the bugs!"
        },
        "files": [{
            "filename": "spam/eggs.py",
            "status": "modified",
            "raw_url": "https://github.com/raw/1/spam/eggs.py"
        }]
    }
    httpretty.register_uri(httpretty.GET,
                           "https://api.github.com/commits/1",
                           body=json.dumps(commit),
                           content_type="application/json")
    eggs_py = "if foo == bar:\n  print('derp')\n"
    httpretty.register_uri(httpretty.GET,
                           "https://github.com/raw/1/spam/eggs.py",
                           body=eggs_py,
                           content_type="text/plain")
    httpretty.register_uri(httpretty.POST,
                           "https://api.github.com/commits/1/comments",
                           status=201,
                           body=json.dumps({"id": 1}),
                           content_type="application/json")
    status = {"id": 1, "state": "success"}
    httpretty.register_uri(httpretty.POST,
                           "https://api.github.com/statuses/1",
                           status=201,
                           body=json.dumps(status),
                           content_type="application/json")

    cs = CommitStatus(repository, "1", "https://github.com/commits/1", {
        "message": [],
        "files": None
    })
    session.add(cs)
    session.commit()
    assert_that(cs.is_pending(), equal_to(False))

    httpretty.enable()
    push(cs.id, "https://api.github.com/commits/1",
         "https://api.github.com/statuses/1", {"repository": repository.id})
    httpretty.disable()

    latest_requests = httpretty.HTTPretty.latest_requests
    assert_that(len(latest_requests), equal_to(4), "2x GET, 2x POST")

    expected_requests = ["", "", "F821 undefined name 'foo'", "error"]
    for expected, request in zip(expected_requests, latest_requests):
        assert_that(str(request.parsed_body), contains_string(expected))

    cs = CommitStatus.query.filter_by(id=cs.id).first()
    assert_that(cs)
    assert_that(cs.is_pending(), equal_to(False))
    assert_that(cs.content["files"]["spam/eggs.py"]["errors"],
                has_item("1: D100 Missing docstring in public module"))