core/tests/components/surepetcare/conftest.py

24 lines
647 B
Python
Raw Normal View History

"""Define fixtures available for all tests."""
from unittest.mock import patch
2021-01-01 21:31:56 +00:00
import pytest
from surepy import MESTART_RESOURCE
from . import MOCK_API_DATA
2021-09-06 20:36:45 +00:00
async def _mock_call(method, resource):
if method == "GET" and resource == MESTART_RESOURCE:
return {"data": MOCK_API_DATA}
@pytest.fixture
async def surepetcare():
"""Mock the SurePetcare for easier testing."""
2021-09-06 20:36:45 +00:00
with patch("surepy.SureAPIClient", autospec=True) as mock_client_class:
client = mock_client_class.return_value
2021-09-06 20:36:45 +00:00
client.resources = {}
client.call = _mock_call
client.get_token.return_value = "token"
yield client