File: test_scan.py

package info (click to toggle)
python-aioguardian 2023.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 772 kB
  • sloc: python: 1,387; sh: 45; makefile: 13
file content (46 lines) | stat: -rw-r--r-- 1,393 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
"""Test the scan command."""
from unittest.mock import MagicMock

import pytest

from aioguardian import Client
from aioguardian.errors import CommandError
from tests.common import load_fixture


@pytest.mark.asyncio
@pytest.mark.parametrize(
    "command_response", [load_fixture("wifi_scan_failure_response.json").encode()]
)
async def test_scan_failure(mock_datagram_client: MagicMock) -> None:
    """Test the wifi_scan command failing.

    Args:
        mock_datagram_client: A mocked UDP client.
    """
    with mock_datagram_client:
        with pytest.raises(CommandError) as err:
            async with Client("192.168.1.100") as client:
                _ = await client.wifi.scan()

        assert str(err.value) == (
            "WIFI_SCAN command failed (response: {'command': 37, 'status': 'error'})"
        )


@pytest.mark.asyncio
@pytest.mark.parametrize(
    "command_response", [load_fixture("wifi_scan_success_response.json").encode()]
)
async def test_scan_success(mock_datagram_client: MagicMock) -> None:
    """Test the wifi_scan command succeeding.

    Args:
        mock_datagram_client: A mocked UDP client.
    """
    with mock_datagram_client:
        async with Client("192.168.1.100") as client:
            wifi_scan_response = await client.wifi.scan()

        assert wifi_scan_response["command"] == 37
        assert wifi_scan_response["status"] == "ok"