Debian Codegraph @

tests/github/test_construction.py

raw
1 """Construction tests for the main class."""
2 # pylint: disable=protected-access,missing-function-docstring
3 from __future__ import annotations
4
5 from unittest.mock import patch
6
7 import aiohttp
8 import pytest
9
10 from aiogithubapi import GitHubAPI
11
12 from tests.common import TOKEN
13
14
15 @pytest.mark.asyncio
16 async def test_session_creation():
17 github = GitHubAPI()
18 assert github._session
19 assert isinstance(github._session, aiohttp.ClientSession)
20
21 assert not github._session.closed
22 await github.close_session()
23 assert github._session.closed
24
25
26 @pytest.mark.asyncio
27 async def test_session_pass():
28 async with aiohttp.ClientSession() as session:
29 github = GitHubAPI(session=session)
30 assert github._session is session
31
32
33 @pytest.mark.asyncio
34 async def test_session_creation_with_enter():
35 async with GitHubAPI() as github:
36 assert github._session
37 assert isinstance(github._session, aiohttp.ClientSession)
38 assert not github._session.closed
39
40 assert github._session.closed
41
42
43 @pytest.mark.asyncio
44 async def test_token():
45 assert GitHubAPI()._client._base_request_data.token is None
46 assert GitHubAPI(token=TOKEN)._client._base_request_data.token == TOKEN
47 with patch("os.environ", {"GITHUB_TOKEN": TOKEN}):
48 assert GitHubAPI()._client._base_request_data.token == TOKEN
49
50
51 @pytest.mark.asyncio
52 async def test_api_version():
53 assert GitHubAPI()._client._base_request_data.token is None
54 assert GitHubAPI(token=TOKEN, api_version="3000-01-01")._client._base_request_data.api_version == "3000-01-01"