| 1 |
"""Construction tests for the device object.""" |
| 2 |
# pylint: disable=protected-access,missing-function-docstring |
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
import aiohttp |
| 6 |
import pytest |
| 7 |
|
| 8 |
from aiogithubapi import GitHubClientKwarg, GitHubDeviceAPI |
| 9 |
|
| 10 |
from tests.common import CLIENT_ID |
| 11 |
|
| 12 |
|
| 13 |
@pytest.mark.asyncio |
| 14 |
async def test_session_creation(): |
| 15 |
device = GitHubDeviceAPI(client_id=CLIENT_ID) |
| 16 |
assert device._session |
| 17 |
assert isinstance(device._session, aiohttp.ClientSession) |
| 18 |
|
| 19 |
assert not device._session.closed |
| 20 |
await device.close_session() |
| 21 |
assert device._session.closed |
| 22 |
|
| 23 |
|
| 24 |
@pytest.mark.asyncio |
| 25 |
async def test_session_pass(): |
| 26 |
async with aiohttp.ClientSession() as session: |
| 27 |
device = GitHubDeviceAPI(client_id=CLIENT_ID, session=session) |
| 28 |
assert device._session is session |
| 29 |
|
| 30 |
|
| 31 |
@pytest.mark.asyncio |
| 32 |
async def test_session_creation_with_enter(): |
| 33 |
async with GitHubDeviceAPI(client_id=CLIENT_ID) as device: |
| 34 |
assert device._session |
| 35 |
assert isinstance(device._session, aiohttp.ClientSession) |
| 36 |
assert not device._session.closed |
| 37 |
|
| 38 |
assert device._session.closed |
| 39 |
|
| 40 |
|
| 41 |
@pytest.mark.asyncio |
| 42 |
async def test_base_url(): |
| 43 |
async with GitHubDeviceAPI(client_id=CLIENT_ID) as device: |
| 44 |
assert device._client._base_request_data.base_url == "https://github.com" |
| 45 |
|
| 46 |
async with GitHubDeviceAPI( |
| 47 |
client_id=CLIENT_ID, **{GitHubClientKwarg.BASE_URL: "https://example.com"} |
| 48 |
) as device: |
| 49 |
assert device._client._base_request_data.base_url == "https://example.com" |