File: test_wsrpc.py

package info (click to toggle)
python-aioshelly 13.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 732 kB
  • sloc: python: 6,867; makefile: 7; sh: 3
file content (48 lines) | stat: -rw-r--r-- 1,765 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Tests for rpc_device.wsrpc module."""

import pytest

from aioshelly.exceptions import InvalidAuthError

from . import load_device_fixture
from .conftest import WsRPCMocker


@pytest.mark.asyncio
async def test_device_wscall_get_config(ws_rpc: WsRPCMocker) -> None:
    """Test wscall."""
    config_response = await load_device_fixture("shellyplugus", "Shelly.GetConfig")
    calls = [("Shelly.GetConfig", None)]
    responses = [config_response]
    results = await ws_rpc.calls_with_mocked_responses(calls, responses)
    assert results[0] == config_response["result"]


@pytest.mark.asyncio
async def test_device_wscall_no_auth_retry(ws_rpc: WsRPCMocker) -> None:
    """Test wscall when auth is not set."""
    cover_close_auth_fail = await load_device_fixture(
        "shellyplus2pm", "Cover.Close_auth_failure"
    )
    cover_close_success = await load_device_fixture(
        "shellyplus2pm", "Cover.Close_success"
    )
    calls = [("Cover.Close", {"id": 0})]
    responses = [cover_close_auth_fail, cover_close_success]
    with pytest.raises(InvalidAuthError):
        await ws_rpc.calls_with_mocked_responses(calls, responses)


@pytest.mark.asyncio
async def test_device_wscall_auth_retry(ws_rpc_with_auth: WsRPCMocker) -> None:
    """Test wscall when auth is set and a retry works."""
    cover_close_auth_fail = await load_device_fixture(
        "shellyplus2pm", "Cover.Close_auth_failure"
    )
    cover_close_success = await load_device_fixture(
        "shellyplus2pm", "Cover.Close_success"
    )
    calls = [("Cover.Close", {"id": 0})]
    responses = [cover_close_auth_fail, cover_close_success]
    results = await ws_rpc_with_auth.calls_with_mocked_responses(calls, responses)
    assert results[0] == cover_close_success["result"]