def test_has_internal_pr_cover_letter(reqctx, requests_mocker):
    pr = make_pull_request(
        user="******", body="omg this code is teh awesomezors",
        head_ref="patch-1",
    )
    requests_mocker.get(
        "https://api.github.com/user",
        json={"login": "******"},
        headers={"Content-Type": "application/json"},
    )
    requests_mocker.get(
        "https://raw.githubusercontent.com/different_user/edx-platform/patch-1/.coverletter.md.j2",
        status_code=404,
    )

    with reqctx:
        comment_body = github_internal_cover_letter(pr)
    comments_json = [
        {
            "user": {
                "login": "******",
            },
            "body": comment_body,
        },
    ]
    requests_mocker.get(
        "https://api.github.com/repos/edx/edx-platform/issues/1/comments",
        json=comments_json,
        headers={"Content-Type": "application/json"},
    )

    with reqctx:
        result = has_internal_cover_letter(pr)
    assert result is True
def test_has_internal_pr_cover_letter(reqctx, requests_mocker):
    pr = make_pull_request(
        user="******",
        body="omg this code is teh awesomezors",
        head_ref="patch-1",
    )
    requests_mocker.get(
        "https://api.github.com/user",
        json={"login": "******"},
        headers={"Content-Type": "application/json"},
    )
    requests_mocker.get(
        "https://raw.githubusercontent.com/different_user/edx-platform/patch-1/.pr_cover_letter.md.j2",
        text="Fancy cover letter!",
    )

    with reqctx:
        comment_body = github_internal_cover_letter(pr)
    comments_json = [
        {
            "user": {
                "login": "******",
            },
            "body": comment_body,
        },
    ]
    requests_mocker.get(
        "https://api.github.com/repos/edx/edx-platform/issues/1/comments",
        json=comments_json,
        headers={"Content-Type": "application/json"},
    )

    with reqctx:
        result = has_internal_cover_letter(pr)
    assert result is True
def test_has_internal_pr_cover_letter_false(reqctx, requests_mocker):
    pr = make_pull_request(
        user="******", body="omg this code is teh awesomezors",
    )
    requests_mocker.get(
        "https://api.github.com/user",
        json={"login": "******"},
        headers={"Content-Type": "application/json"},
    )
    with reqctx:
        result = has_internal_cover_letter(pr)
    assert result is False
def test_has_internal_pr_cover_letter_false(reqctx, requests_mocker):
    pr = make_pull_request(
        user="******",
        body="omg this code is teh awesomezors",
    )
    requests_mocker.get(
        "https://api.github.com/user",
        json={"login": "******"},
        headers={"Content-Type": "application/json"},
    )
    with reqctx:
        result = has_internal_cover_letter(pr)
    assert result is False