2021-11-26 21:44:49 +00:00
|
|
|
"""Fixtures for UniFi Network methods."""
|
2021-03-18 14:13:22 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2021-01-01 21:31:56 +00:00
|
|
|
from unittest.mock import patch
|
2020-01-30 22:06:43 +00:00
|
|
|
|
2021-03-05 20:28:41 +00:00
|
|
|
from aiounifi.websocket import SIGNAL_CONNECTION_STATE, SIGNAL_DATA
|
2021-01-01 21:31:56 +00:00
|
|
|
import pytest
|
2020-04-30 20:29:50 +00:00
|
|
|
|
2020-01-30 22:06:43 +00:00
|
|
|
|
2021-03-05 20:28:41 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def mock_unifi_websocket():
|
|
|
|
"""No real websocket allowed."""
|
|
|
|
with patch("aiounifi.controller.WSClient") as mock:
|
|
|
|
|
2021-03-18 14:13:22 +00:00
|
|
|
def make_websocket_call(data: dict | None = None, state: str = ""):
|
2021-03-05 20:28:41 +00:00
|
|
|
"""Generate a websocket call."""
|
|
|
|
if data:
|
|
|
|
mock.return_value.data = data
|
|
|
|
mock.call_args[1]["callback"](SIGNAL_DATA)
|
|
|
|
elif state:
|
|
|
|
mock.return_value.state = state
|
|
|
|
mock.call_args[1]["callback"](SIGNAL_CONNECTION_STATE)
|
|
|
|
else:
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
yield make_websocket_call
|
|
|
|
|
|
|
|
|
2020-01-30 22:06:43 +00:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def mock_discovery():
|
|
|
|
"""No real network traffic allowed."""
|
|
|
|
with patch(
|
|
|
|
"homeassistant.components.unifi.config_flow.async_discover_unifi",
|
|
|
|
return_value=None,
|
|
|
|
) as mock:
|
|
|
|
yield mock
|