| 1 |
"""Test graphql.""" |
| 2 |
# pylint: disable=missing-docstring |
| 3 |
import pytest |
| 4 |
|
| 5 |
from aiogithubapi import GitHubAPI, GitHubGraphQLException |
| 6 |
from aiogithubapi.graphql_examples.repository_tags import EXAMPLE_QUERY |
| 7 |
|
| 8 |
from tests.common import MockedRequests, MockResponse |
| 9 |
|
| 10 |
|
| 11 |
@pytest.mark.asyncio |
| 12 |
async def test_graphql(github_api: GitHubAPI, mock_requests: MockedRequests): |
| 13 |
response = await github_api.graphql(EXAMPLE_QUERY) |
| 14 |
assert response.status == 200 |
| 15 |
assert isinstance(response.data, dict) |
| 16 |
assert mock_requests.called == 1 |
| 17 |
assert mock_requests.last_request["url"] == "https://api.github.com/graphql" |
| 18 |
|
| 19 |
|
| 20 |
@pytest.mark.asyncio |
| 21 |
async def test_graphql_error( |
| 22 |
github_api: GitHubAPI, |
| 23 |
mock_requests: MockedRequests, |
| 24 |
mock_response: MockResponse, |
| 25 |
): |
| 26 |
mock_response.mock_data = {"errors": [{"message": "test"}]} |
| 27 |
with pytest.raises(GitHubGraphQLException, match="test"): |
| 28 |
await github_api.graphql(EXAMPLE_QUERY) |
| 29 |
|
| 30 |
assert mock_requests.called == 1 |
| 31 |
assert mock_requests.last_request["url"] == "https://api.github.com/graphql" |