Example #1
0
async def test_get_permissions_for_username_missing(
    api_client: Client, mocker: MockFixture, mock_get_token_for_install: None
) -> None:
    not_found = Response()
    not_found.status_code = 404
    mocker.patch("kodiak.queries.http.Session.get", return_value=wrap_future(not_found))
    async with api_client as api_client:
        res = await api_client.get_permissions_for_username("_invalid_username")
    assert res == Permission.NONE
Example #2
0
async def test_get_permissions_for_username_read(
    api_client: Client, mocker: MockFixture, mock_get_token_for_install: None
) -> None:
    response = Response()
    response.status_code = 200
    response._content = PERMISSION_OK_READ_USER_RESPONSE

    mocker.patch("kodiak.queries.http.Session.get", return_value=wrap_future(response))
    async with api_client as api_client:
        res = await api_client.get_permissions_for_username("ghost")
    assert res == Permission.READ
Example #3
0
def generate_page_of_prs(numbers: Iterable[int]) -> Response:
    """
    Create a fake page for the list-pull-requests API.

    This is used by get_open_pull_requests.
    """
    response = Response()
    response.status_code = 200
    prs = [{"number": number, "base": {"ref": "main"}} for number in numbers]
    response._content = json.dumps(prs).encode()
    return response
Example #4
0
async def test_pr_update_ok(
    mocker: MockFixture, event_response: queries.EventInfoResponse, pr: PR
) -> None:
    """
    Update should return true on success
    """
    mocker.patch.object(PR, "get_event", return_value=wrap_future(event_response))
    res = Response()
    res.status_code = 200
    mocker.patch(
        "kodiak.pull_request.queries.Client.merge_branch", return_value=wrap_future(res)
    )

    res = await pr.update()
    assert res, "should be true when we have a successful call"
Example #5
0
async def test_pr_update_bad_merge(
    mocker: MockFixture, event_response: queries.EventInfoResponse, pr: PR
) -> None:
    """
    Update should return false on an error
    """
    mocker.patch.object(PR, "get_event", return_value=wrap_future(event_response))
    res = Response()
    res.status_code = 409
    res._content = b"{}"
    mocker.patch(
        "kodiak.pull_request.queries.Client.merge_branch", return_value=wrap_future(res)
    )

    res = await pr.update()
    assert not res