| 1 |
# pylint: disable=missing-docstring, redefined-outer-name, unused-import |
| 2 |
import json |
| 3 |
|
| 4 |
import aiohttp |
| 5 |
import pytest |
| 6 |
|
| 7 |
from aiogithubapi import AIOGitHubAPIException, AIOGitHubAPINotModifiedException, GitHub |
| 8 |
from aiogithubapi.common.exceptions import AIOGitHubAPIRatelimitException |
| 9 |
|
| 10 |
from tests.common import TOKEN |
| 11 |
from tests.legacy.responses.base import base_response |
| 12 |
|
| 13 |
|
| 14 |
@pytest.mark.asyncio |
| 15 |
async def test_render_markdown(mock_response, base_response, client_session): |
| 16 |
mock_response.mock_data = json.dumps(base_response) |
| 17 |
|
| 18 |
async with GitHub(TOKEN, session=client_session) as github: |
| 19 |
render = await github.render_markdown("test") |
| 20 |
assert github.client.ratelimits.remaining == "4999" |
| 21 |
assert isinstance(render, str) |
| 22 |
|
| 23 |
mock_response.clear() |
| 24 |
mock_response.mock_status = 304 |
| 25 |
|
| 26 |
with pytest.raises(AIOGitHubAPINotModifiedException): |
| 27 |
await github.render_markdown("test", etag=github.client.last_response.etag) |
| 28 |
|
| 29 |
|
| 30 |
@pytest.mark.asyncio |
| 31 |
async def test_render_markdown_rate_limited(mock_response, github): |
| 32 |
mock_response.mock_status = 403 |
| 33 |
with pytest.raises(AIOGitHubAPIRatelimitException): |
| 34 |
await github.render_markdown("test") |
| 35 |
|
| 36 |
|
| 37 |
@pytest.mark.asyncio |
| 38 |
async def test_render_markdown_error(mock_response, client_session): |
| 39 |
mock_response.mock_status = 500 |
| 40 |
|
| 41 |
async with GitHub(TOKEN, session=client_session) as github: |
| 42 |
with pytest.raises(AIOGitHubAPIException): |
| 43 |
await github.render_markdown("test") |