Exemple #1
0
def test_push(app, repository):
    """POST /payload (push) performs the checks"""
    queue = MyQueue()
    # Replace the default Redis queue
    app.config["queue"] = queue

    push_event = {
        "commits": [{
            "id": "1",
            "url": "https://github.com/commits/1"
        }, {
            "id": "2",
            "url": "https://github.com/commits/2"
        }],
        "repository": {
            "name": "test",
            "owner": {
                "name": "invenio"
            }
        }
    }

    tester = app.test_client()
    response = tester.post("/payload",
                           content_type="application/json",
                           headers=(("X-GitHub-Event", "push"),
                                    ("X-GitHub-Delivery", "1")),
                           data=json.dumps(push_event))

    assert_that(response.status_code, equal_to(200))
    body = json.loads(response.data)
    assert_that(body["payload"]["state"], equal_to("pending"))

    cs = CommitStatus.query.filter_by(repository_id=repository.id,
                                      sha="1").first()

    (fn, commit_id, commit_url, status_url, config) = queue.dequeue()
    assert_that(fn, equal_to(push))
    assert_that(commit_id, equal_to(cs.id))
    assert_that(
        commit_url,
        equal_to("https://api.github.com"
                 "/repos/invenio/test/commits/1"))
    assert_that(status_url, contains_string("/invenio/test/commits/1"))

    cs = CommitStatus.query.filter_by(repository_id=repository.id,
                                      sha="2").first()

    (fn, commit_id, commit_url, status_url, config) = queue.dequeue()
    assert_that(fn, equal_to(push))
    assert_that(commit_id, equal_to(cs.id))
    assert_that(
        commit_url,
        equal_to("https://api.github.com"
                 "/repos/invenio/test/commits/2"))
    assert_that(status_url, contains_string("/invenio/test/commits/2"))
Exemple #2
0
def test_push(app, repository):
    """POST /payload (push) performs the checks"""
    queue = MyQueue()
    # Replace the default Redis queue
    app.config["queue"] = queue

    push_event = {
        "commits": [{
            "id": "1",
            "url": "https://github.com/commits/1"
        }, {
            "id": "2",
            "url": "https://github.com/commits/2"
        }],
        "repository": {
            "name": "test",
            "owner": {
                "name": "invenio"
            }
        }
    }

    tester = app.test_client()
    response = tester.post("/payload", content_type="application/json",
                           headers=(("X-GitHub-Event", "push"),
                                    ("X-GitHub-Delivery", "1")),
                           data=json.dumps(push_event))

    assert_that(response.status_code, equal_to(200))
    body = json.loads(response.data)
    assert_that(body["payload"]["state"], equal_to("pending"))

    cs = CommitStatus.query.filter_by(repository_id=repository.id,
                                      sha="1").first()

    (fn, commit_id, commit_url, status_url, config) = queue.dequeue()
    assert_that(fn, equal_to(push))
    assert_that(commit_id, equal_to(cs.id))
    assert_that(commit_url, equal_to("https://api.github.com"
                                     "/repos/invenio/test/commits/1"))
    assert_that(status_url, contains_string("/invenio/test/commits/1"))

    cs = CommitStatus.query.filter_by(repository_id=repository.id,
                                      sha="2").first()

    (fn, commit_id, commit_url, status_url, config) = queue.dequeue()
    assert_that(fn, equal_to(push))
    assert_that(commit_id, equal_to(cs.id))
    assert_that(commit_url, equal_to("https://api.github.com"
                                     "/repos/invenio/test/commits/2"))
    assert_that(status_url, contains_string("/invenio/test/commits/2"))
def test_pull_request(app, owner, repository):
    """POST /payload (pull_request) performs the checks"""
    httpretty.reset()
    queue = MyQueue()
    # Replace the default Redis queue
    app.config["queue"] = queue

    pull_request_event = {
        "action": "opened",
        "number": 1,
        "pull_request": {
            "title": "Lorem ipsum",
            "url": "https://api.github.com/pulls/1",
            "html_url": "https://github.com/pulls/1",
            "commits_url": "https://api.github.com/pulls/1/commits",
            "statuses_url": "https://api.github.com/pulls/1/statuses",
            "head": {
                "sha": "2",
                "label": "spam:wip/my-branch",
                "ref": "wip/my-branch"
            }
        },
        "repository": {
            "name": "test",
            "owner": {
                "login": "******"
            }
        }
    }

    commits = [
        {
            "url": "https://api.github.com/commits/1",
            "sha": "1",
            "html_url": "https://github.com/commits/1",
            "comments_url": "https://api.github.com/commits/1/comments",
            "commit": {
                "message": "herp derp"
            }
        }, {
            "url": "https://api.github.com/commits/2",
            "sha": "2",
            "html_url": "https://github.com/commits/2",
            "comments_url": "https://api.github.com/commits/2/comments",
            "commit": {
                "message": "fix all the bugs!"
            }
        }
    ]
    httpretty.register_uri(httpretty.GET,
                           "https://api.github.com/pulls/1/commits",
                           body=json.dumps(commits),
                           content_type="application/json")

    tester = app.test_client()
    httpretty.enable()
    response = tester.post("/payload", content_type="application/json",
                           headers=(("X-GitHub-Event", "pull_request"),
                                    ("X-GitHub-Delivery", "1")),
                           data=json.dumps(pull_request_event))
    httpretty.disable()

    assert_that(response.status_code, equal_to(200))
    body = json.loads(response.data)
    assert_that(body["payload"]["state"], equal_to("pending"))

    (fn, bs_id, pull_request_url, status_url, config) = queue.dequeue()
    assert_that(fn, equal_to(pull_request))
    assert_that(bs_id, greater_than(0))
    assert_that(pull_request_url,
                equal_to("https://api.github.com/pulls/1"))

    cs = CommitStatus.query.filter_by(repository_id=repository.id,
                                      sha="1").first()
    assert_that(cs)
    assert_that(cs.state, equal_to("pending"))

    cs = CommitStatus.query.filter_by(repository_id=repository.id,
                                      sha="2").first()
    assert_that(cs)
    assert_that(cs.state, equal_to("pending"))

    bs = BranchStatus.query.filter_by(commit_id=cs.id,
                                      name="spam:wip/my-branch").first()
    assert_that(bs)
    assert_that(bs.is_pending())
    assert_that(bs.state, equal_to("pending"))
Exemple #4
0
def test_pull_request(app, owner, repository):
    """POST /payload (pull_request) performs the checks"""
    httpretty.reset()
    queue = MyQueue()
    # Replace the default Redis queue
    app.config["queue"] = queue

    pull_request_event = {
        "action": "opened",
        "number": 1,
        "pull_request": {
            "title": "Lorem ipsum",
            "url": "https://api.github.com/pulls/1",
            "html_url": "https://github.com/pulls/1",
            "commits_url": "https://api.github.com/pulls/1/commits",
            "statuses_url": "https://api.github.com/pulls/1/statuses",
            "head": {
                "sha": "2",
                "label": "spam:wip/my-branch",
                "ref": "wip/my-branch"
            }
        },
        "repository": {
            "name": "test",
            "owner": {
                "login": "******"
            }
        }
    }

    commits = [{
        "url": "https://api.github.com/commits/1",
        "sha": "1",
        "html_url": "https://github.com/commits/1",
        "comments_url": "https://api.github.com/commits/1/comments",
        "commit": {
            "message": "herp derp"
        }
    }, {
        "url": "https://api.github.com/commits/2",
        "sha": "2",
        "html_url": "https://github.com/commits/2",
        "comments_url": "https://api.github.com/commits/2/comments",
        "commit": {
            "message": "fix all the bugs!"
        }
    }]
    httpretty.register_uri(httpretty.GET,
                           "https://api.github.com/pulls/1/commits",
                           body=json.dumps(commits),
                           content_type="application/json")

    tester = app.test_client()
    httpretty.enable()
    response = tester.post("/payload",
                           content_type="application/json",
                           headers=(("X-GitHub-Event", "pull_request"),
                                    ("X-GitHub-Delivery", "1")),
                           data=json.dumps(pull_request_event))
    httpretty.disable()

    assert_that(response.status_code, equal_to(200))
    body = json.loads(response.data)
    assert_that(body["payload"]["state"], equal_to("pending"))

    (fn, bs_id, pull_request_url, status_url, config) = queue.dequeue()
    assert_that(fn, equal_to(pull_request))
    assert_that(bs_id, greater_than(0))
    assert_that(pull_request_url, equal_to("https://api.github.com/pulls/1"))

    cs = CommitStatus.query.filter_by(repository_id=repository.id,
                                      sha="1").first()
    assert_that(cs)
    assert_that(cs.state, equal_to("pending"))

    cs = CommitStatus.query.filter_by(repository_id=repository.id,
                                      sha="2").first()
    assert_that(cs)
    assert_that(cs.state, equal_to("pending"))

    bs = BranchStatus.query.filter_by(commit_id=cs.id,
                                      name="spam:wip/my-branch").first()
    assert_that(bs)
    assert_that(bs.is_pending())
    assert_that(bs.state, equal_to("pending"))