File: conftest.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 (53 lines) | stat: -rw-r--r-- 1,459 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
49
50
51
52
53
"""Define generic fixtures for tests."""
# pylint: disable=redefined-outer-name
from collections.abc import Generator
from unittest.mock import AsyncMock, MagicMock, patch

import pytest


@pytest.fixture()
def command_response() -> MagicMock:
    """Define a fixture for the JSON response payload of a command.

    Returns:
        A mocked command response.
    """
    return MagicMock()


@pytest.fixture()
def mock_datagram_client(recv_response: AsyncMock) -> Generator:
    """Define a mocked datagram client.

    Args:
        recv_response: A mocked instance of a socket recv operation.
    """
    mock_datagram_client = MagicMock()
    mock_datagram_client.connect = AsyncMock()
    mock_datagram_client.recv = recv_response
    mock_datagram_client.send = AsyncMock()
    mock_datagram_client.close = MagicMock()

    with patch("asyncio_dgram.connect", return_value=mock_datagram_client):
        yield mock_datagram_client


@pytest.fixture()
def recv_response(command_response: MagicMock, remote_addr_response: str) -> AsyncMock:
    """Define a response from the socket.

    Returns:
        A mocked instance of a socket recv operation.
    """
    return AsyncMock(return_value=(command_response, remote_addr_response))


@pytest.fixture()
def remote_addr_response() -> str:
    """Define an IP address for the Guardian device.

    Returns:
        A response for getting the valve's remote IP address.
    """
    return "192.168.1.100"