Use a future for mock coro (#34989)

This commit is contained in:
Paulus Schoutsen 2020-04-30 16:31:00 -07:00 committed by GitHub
parent ba7391528f
commit 76f392476b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 154 additions and 262 deletions

View file

@ -15,7 +15,7 @@ from homeassistant.components.http.view import (
)
from homeassistant.exceptions import ServiceNotFound, Unauthorized
from tests.common import mock_coro_func
from tests.async_mock import AsyncMock
@pytest.fixture
@ -38,7 +38,7 @@ async def test_handling_unauthorized(mock_request):
"""Test handling unauth exceptions."""
with pytest.raises(HTTPUnauthorized):
await request_handler_factory(
Mock(requires_auth=False), mock_coro_func(exception=Unauthorized)
Mock(requires_auth=False), AsyncMock(side_effect=Unauthorized)
)(mock_request)
@ -46,7 +46,7 @@ async def test_handling_invalid_data(mock_request):
"""Test handling unauth exceptions."""
with pytest.raises(HTTPBadRequest):
await request_handler_factory(
Mock(requires_auth=False), mock_coro_func(exception=vol.Invalid("yo"))
Mock(requires_auth=False), AsyncMock(side_effect=vol.Invalid("yo"))
)(mock_request)
@ -55,5 +55,5 @@ async def test_handling_service_not_found(mock_request):
with pytest.raises(HTTPInternalServerError):
await request_handler_factory(
Mock(requires_auth=False),
mock_coro_func(exception=ServiceNotFound("test", "test")),
AsyncMock(side_effect=ServiceNotFound("test", "test")),
)(mock_request)