Beispiel #1
0
async def test_error_while_waiting(
    github_device_api: GitHubDeviceAPI,
    mock_response: MockResponse,
):
    mock_response.mock_data = {
        "error": "any",
        "error_description": "Any error message"
    }
    with pytest.raises(GitHubException, match="Any error message"):
        await github_device_api.activation(device_code=DEVICE_CODE)
Beispiel #2
0
async def test_list_empty(
    github_api: GitHubAPI,
    mock_requests: MockedRequests,
    mock_response: MockResponse,
):
    mock_response.mock_data = []
    response = await github_api.repos.pulls.list(TEST_REPOSITORY_NAME)
    assert response.status == 200
    assert isinstance(response.data, list)
    assert len(response.data) == 0
    assert mock_requests.called == 1
    assert (mock_requests.last_request["url"] ==
            "https://api.github.com/repos/octocat/hello-world/pulls")
Beispiel #3
0
async def test_error_message_handling(
    github_api: GitHubAPI,
    mock_response: MockResponse,
    message: str,
    exception: GitHubException,
):

    mock_response.mock_data = {
        "message": message,
        "documentation_url": "https://example.com",
    }

    with pytest.raises(exception):
        await github_api.generic("/generic")
Beispiel #4
0
async def test_status_code_handling(
    github_api: GitHubAPI,
    mock_response: MockResponse,
    status: HttpStatusCode,
    exception: GitHubException,
):

    mock_response.mock_status = status
    mock_response.mock_data = {
        "message": "Error",
        "documentation_url": "https://example.com",
    }

    with pytest.raises(exception):
        await github_api.generic("/generic")
Beispiel #5
0
async def test_get(
    github_api: GitHubAPI,
    mock_requests: MockedRequests,
    mock_response: MockResponse,
):
    mock_response.mock_data = load_fixture(
        "repos_octocat_hello-world_issues.json",
        asjson=True,
        legacy=False,
    )[0]
    response = await github_api.repos.issues.get(TEST_REPOSITORY_NAME, 1)
    assert response.status == 200
    assert isinstance(response.data, GitHubIssueModel)
    assert response.data.title == "Test issue"
    assert mock_requests.called == 1
    assert (mock_requests.last_request["url"] ==
            "https://api.github.com/repos/octocat/hello-world/issues/1")
Beispiel #6
0
async def test_update_comment(
    github_api: GitHubAPI,
    mock_requests: MockedRequests,
    mock_response: MockResponse,
):
    mock_response.mock_data = load_fixture(
        "repos_octocat_hello-world_issues_1_comments.json",
        asjson=True,
        legacy=False,
    )[0]
    response = await github_api.repos.issues.update_comment(
        TEST_REPOSITORY_NAME, 1, {"title": "test"})
    assert response.status == 200
    assert isinstance(response.data, GitHubIssueCommentModel)
    assert response.data.body == "No logs, no issue!"
    assert mock_requests.called == 1
    assert mock_requests.last_request["method"] == "patch"
    assert mock_requests.last_request["json"] == {"title": "test"}
    assert (
        mock_requests.last_request["url"] ==
        "https://api.github.com/repos/octocat/hello-world/issues/comments/1")