abmantis / whirlpool-sixth-sense

Whirlpool unofficial API for 6th Sense appliances
MIT License
13 stars 12 forks source link

Tests fail on 0.17.1 #15

Closed mweinelt closed 1 year ago

mweinelt commented 1 year ago

There is something wrong with the MockResponse and it's async context handler..

❯ pytest
==================================================================================== test session starts ====================================================================================
platform linux -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0
rootdir: /tmp/whirlpool-sixth-sense
plugins: asyncio-0.19.0, mock-3.8.2
asyncio: mode=strict
collected 6 items                                                                                                                                                                           

tests/test_aircon.py FF                                                                                                                                                               [ 33%]
tests/test_auth.py ..                                                                                                                                                                 [ 66%]
tests/test_oven.py FF                                                                                                                                                                 [100%]

========================================================================================= FAILURES ==========================================================================================
______________________________________________________________________________________ test_attributes ______________________________________________________________________________________

caplog = <_pytest.logging.LogCaptureFixture object at 0x7efc915db0d0>, aio_httpclient = <MagicMock name='ClientSession()' id='139623235687744'>

    async def test_attributes(caplog, aio_httpclient):
        caplog.set_level(logging.DEBUG)
        auth = MagicMock()

        aio_httpclient.get.return_value = MockResponse(json.dumps(DATA1), 200)

        aircon = Aircon(BackendSelectorMock(), auth, SAID, None)
>       await aircon.connect()

tests/test_aircon.py:100: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
whirlpool/appliance.py:142: in connect
    await self.start_event_listener()
whirlpool/appliance.py:161: in start_event_listener
    await self._getWebsocketUrl(),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <whirlpool.aircon.Aircon object at 0x7efc90d7da20>

    async def _getWebsocketUrl(self):
        async with aiohttp.ClientSession(headers=self._create_headers()) as session:
            DEFAULT_WS_URL = "wss://ws.emeaprod.aws.whrcloud.com/appliance/websocket"
>           async with session.get(
                f"{self._backend_selector.base_url}/api/v1/client_auth/webSocketUrl"
            ) as r:
E           AttributeError: __aenter__

whirlpool/appliance.py:67: AttributeError
_______________________________________________________________________________________ test_setters ________________________________________________________________________________________

caplog = <_pytest.logging.LogCaptureFixture object at 0x7efc90c8fb20>, aio_httpclient = <MagicMock name='ClientSession()' id='139623225939504'>

    async def test_setters(caplog, aio_httpclient):
        caplog.set_level(logging.DEBUG)
        auth = MagicMock()

        aio_httpclient.get.return_value = MockResponse(json.dumps(DATA1), 200)
        aio_httpclient.post.return_value = MockResponse("", 200)

        cmd_data = {
            "header": {"said": SAID, "command": "setAttributes"},
        }

        aircon = Aircon(BackendSelectorMock(), auth, SAID, None)
>       await aircon.connect()

tests/test_aircon.py:150: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
whirlpool/appliance.py:142: in connect
    await self.start_event_listener()
whirlpool/appliance.py:161: in start_event_listener
    await self._getWebsocketUrl(),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <whirlpool.aircon.Aircon object at 0x7efc90c04580>

    async def _getWebsocketUrl(self):
        async with aiohttp.ClientSession(headers=self._create_headers()) as session:
            DEFAULT_WS_URL = "wss://ws.emeaprod.aws.whrcloud.com/appliance/websocket"
>           async with session.get(
                f"{self._backend_selector.base_url}/api/v1/client_auth/webSocketUrl"
            ) as r:
E           AttributeError: __aenter__

whirlpool/appliance.py:67: AttributeError
______________________________________________________________________________________ test_attributes ______________________________________________________________________________________

caplog = <_pytest.logging.LogCaptureFixture object at 0x7efc90ca97e0>, aio_httpclient = <MagicMock name='ClientSession()' id='139623225719248'>

    async def test_attributes(caplog, aio_httpclient):
        caplog.set_level(logging.DEBUG)
        auth = MagicMock()

        aio_httpclient.get.return_value = MockResponse(json.dumps(DATA1), 200)

        oven = Oven(BackendSelectorMock(), auth, SAID, None)
>       await oven.connect()

tests/test_oven.py:771: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
whirlpool/appliance.py:142: in connect
    await self.start_event_listener()
whirlpool/appliance.py:161: in start_event_listener
    await self._getWebsocketUrl(),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <whirlpool.oven.Oven object at 0x7efc90c7a8f0>

    async def _getWebsocketUrl(self):
        async with aiohttp.ClientSession(headers=self._create_headers()) as session:
            DEFAULT_WS_URL = "wss://ws.emeaprod.aws.whrcloud.com/appliance/websocket"
>           async with session.get(
                f"{self._backend_selector.base_url}/api/v1/client_auth/webSocketUrl"
            ) as r:
E           AttributeError: __aenter__

whirlpool/appliance.py:67: AttributeError
_______________________________________________________________________________________ test_setters ________________________________________________________________________________________

caplog = <_pytest.logging.LogCaptureFixture object at 0x7efc90d07c70>, aio_httpclient = <MagicMock name='ClientSession()' id='139623226441104'>

    async def test_setters(caplog, aio_httpclient):
        caplog.set_level(logging.DEBUG)
        auth = MagicMock()

        aio_httpclient.get.return_value = MockResponse(json.dumps(DATA2), 200)
        aio_httpclient.post.return_value = MockResponse("", 200)

        cmd_data = {
            "header": {"said": SAID, "command": "setAttributes"},
        }

        oven = Oven(BackendSelectorMock(), auth, SAID, None)
>       await oven.connect()

tests/test_oven.py:836: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
whirlpool/appliance.py:142: in connect
    await self.start_event_listener()
whirlpool/appliance.py:161: in start_event_listener
    await self._getWebsocketUrl(),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <whirlpool.oven.Oven object at 0x7efc90c94670>

    async def _getWebsocketUrl(self):
        async with aiohttp.ClientSession(headers=self._create_headers()) as session:
            DEFAULT_WS_URL = "wss://ws.emeaprod.aws.whrcloud.com/appliance/websocket"
>           async with session.get(
                f"{self._backend_selector.base_url}/api/v1/client_auth/webSocketUrl"
            ) as r:
E           AttributeError: __aenter__

whirlpool/appliance.py:67: AttributeError
===================================================================================== warnings summary ======================================================================================
tests/test_aircon.py::test_attributes
tests/test_aircon.py::test_setters
tests/test_oven.py::test_attributes
tests/test_oven.py::test_setters
  /tmp/whirlpool-sixth-sense/whirlpool/appliance.py:67: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
    async with session.get(
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================================================================================== short test summary info ==================================================================================
FAILED tests/test_aircon.py::test_attributes - AttributeError: __aenter__
FAILED tests/test_aircon.py::test_setters - AttributeError: __aenter__
FAILED tests/test_oven.py::test_attributes - AttributeError: __aenter__
FAILED tests/test_oven.py::test_setters - AttributeError: __aenter__
========================================================================== 4 failed, 2 passed, 4 warnings in 0.25s ==========================================================================
abmantis commented 1 year ago

All tests passing now. Thanks for the report!