mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
use asyncmock from unittest library
This commit is contained in:
parent
9c5a9f5837
commit
b94179e071
@ -42,22 +42,6 @@ def anyvar(cls: Type[T], strict: bool = False) -> T:
|
|||||||
return AnyVar()
|
return AnyVar()
|
||||||
|
|
||||||
|
|
||||||
@pytest.helpers.register
|
|
||||||
class AsyncMock(MagicMock):
|
|
||||||
"""
|
|
||||||
async magic mock object
|
|
||||||
"""
|
|
||||||
|
|
||||||
async def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
|
||||||
"""
|
|
||||||
async call function
|
|
||||||
:param args:
|
|
||||||
:param kwargs:
|
|
||||||
:return:
|
|
||||||
"""
|
|
||||||
return MagicMock.__call__(self, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
# generic fixtures
|
# generic fixtures
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def configuration(resource_path_root: Path) -> Configuration:
|
def configuration(resource_path_root: Path) -> Configuration:
|
||||||
|
@ -4,6 +4,7 @@ import pytest
|
|||||||
from aiohttp.web_exceptions import HTTPBadRequest
|
from aiohttp.web_exceptions import HTTPBadRequest
|
||||||
from pytest_mock import MockerFixture
|
from pytest_mock import MockerFixture
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from ahriman.web.middlewares.exception_handler import exception_handler
|
from ahriman.web.middlewares.exception_handler import exception_handler
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ async def test_exception_handler(aiohttp_request: Any, mocker: MockerFixture) ->
|
|||||||
"""
|
"""
|
||||||
must pass success response
|
must pass success response
|
||||||
"""
|
"""
|
||||||
request_handler = pytest.helpers.AsyncMock()
|
request_handler = AsyncMock()
|
||||||
logging_mock = mocker.patch("logging.Logger.exception")
|
logging_mock = mocker.patch("logging.Logger.exception")
|
||||||
|
|
||||||
handler = exception_handler(logging.getLogger())
|
handler = exception_handler(logging.getLogger())
|
||||||
@ -24,7 +25,7 @@ async def test_exception_handler_client_error(aiohttp_request: Any, mocker: Mock
|
|||||||
"""
|
"""
|
||||||
must pass client exception
|
must pass client exception
|
||||||
"""
|
"""
|
||||||
request_handler = pytest.helpers.AsyncMock()
|
request_handler = AsyncMock()
|
||||||
request_handler.side_effect = HTTPBadRequest()
|
request_handler.side_effect = HTTPBadRequest()
|
||||||
logging_mock = mocker.patch("logging.Logger.exception")
|
logging_mock = mocker.patch("logging.Logger.exception")
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ async def test_exception_handler_server_error(aiohttp_request: Any, mocker: Mock
|
|||||||
"""
|
"""
|
||||||
must log server exception and re-raise it
|
must log server exception and re-raise it
|
||||||
"""
|
"""
|
||||||
request_handler = pytest.helpers.AsyncMock()
|
request_handler = AsyncMock()
|
||||||
request_handler.side_effect = Exception()
|
request_handler.side_effect = Exception()
|
||||||
logging_mock = mocker.patch("logging.Logger.exception")
|
logging_mock = mocker.patch("logging.Logger.exception")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user