Skip to content

Commit

Permalink
🔥Modify tests for 1.0beta
Browse files Browse the repository at this point in the history
  • Loading branch information
GLEF1X committed Jun 5, 2021
1 parent 71f1bc7 commit bef13c0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
25 changes: 20 additions & 5 deletions tests/test_api/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ async def test_create_api(self):
# initially session is None,
# it's done to save performance and
# it creates new session when you make a request (API method call)
assert api.session is None
assert api.request_manager._session is None

# such a session is created under the hood(when you call API method)
api._requests.create_session()
await api._requests.create_session()

# And now it's aiohttp.ClientSession instance
assert isinstance(api.session, aiohttp.ClientSession)
assert isinstance(api.request_manager._session, aiohttp.ClientSession)

assert isinstance(api._router, QiwiRouter)
assert isinstance(api._requests, RequestManager)
Expand All @@ -55,13 +55,28 @@ async def test_close_session(self):
from tests.types.dataset import API_DATA
api = QiwiWrapper(**API_DATA)

api._requests.create_session()
await api._requests.create_session()

aiohttp_session = api.session
aiohttp_session = api.request_manager._session

with patch("aiohttp.ClientSession.close",
new=CoroutineMock()) as mocked_close:
await aiohttp_session.close()
mocked_close.assert_called_once()

await api.close()


class TestContextMixin:

def test_get_from_context(self):
from tests.types.dataset import API_DATA
QiwiWrapper.set_current(QiwiWrapper(**API_DATA))
instance = QiwiWrapper.get_current()
assert isinstance(instance, QiwiWrapper)

def test_implicit_get_from_context(self):
from tests.types.dataset import API_DATA
QiwiWrapper(**API_DATA)
assert isinstance(QiwiWrapper.get_current(), QiwiWrapper)

6 changes: 3 additions & 3 deletions tests/test_dispatcher/test_polling.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import asyncio
from datetime import datetime
from typing import Dict

import pytest
import timeout_decorator
from _pytest.fixtures import SubRequest

from glQiwiApi import QiwiWrapper
from glQiwiApi import types
Expand All @@ -23,7 +23,7 @@


@pytest.fixture(name='api')
async def api_fixture(credentials: Dict[str, str]):
async def api_fixture(credentials: dict, request: SubRequest, capsys):
""" Api fixture """
_wrapper = QiwiWrapper(**credentials)
yield _wrapper
Expand All @@ -39,7 +39,7 @@ class TestPolling:

@timeout_decorator.timeout(5)
def _start_polling(self, api: QiwiWrapper):
from glQiwiApi.core import executor
from glQiwiApi.utils import executor

self._handled = False

Expand Down
4 changes: 2 additions & 2 deletions tests/test_qiwi/test_sync_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ def test_is_session_closing(self, api: QiwiWrapper):
# Send request to API
sync(api.get_balance)

api_session = api.session
api_session = api.request_manager._session

assert isinstance(api_session, aiohttp.ClientSession)

# Send new request to API

sync(api.get_balance)

new_session = api.session
new_session = api.request_manager._session

assert api_session != new_session
8 changes: 6 additions & 2 deletions tests/test_qiwi/test_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import datetime
import pathlib
import uuid
from typing import Dict, Union
from typing import Union

import pytest
from _pytest.capture import CaptureFixture
from _pytest.monkeypatch import MonkeyPatch

from glQiwiApi import QiwiWrapper
from glQiwiApi import types, InvalidData
Expand All @@ -12,7 +14,8 @@


@pytest.fixture(name='api')
async def api_fixture(credentials: Dict[str, str]):
async def api_fixture(credentials: dict, capsys: CaptureFixture,
monkeypatch: MonkeyPatch):
""" Api fixture """
_wrapper = QiwiWrapper(**credentials)
yield _wrapper
Expand Down Expand Up @@ -223,6 +226,7 @@ async def test_check_p2p_bill_status(api: QiwiWrapper):
async def test_check_p2p_on_object(api: QiwiWrapper):
async with api:
bill = await api.create_p2p_bill(amount=1)
assert isinstance(bill, types.Bill)
result = await bill.paid

assert isinstance(result, bool)
Expand Down

0 comments on commit bef13c0

Please sign in to comment.