Exemple #1
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"))
Exemple #2
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"))
Exemple #3
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"))
Exemple #4
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"))