* Increase coverage of init * Increase coverage of config_flow * Improve coverage of controller * Minor improvement to switch test * Fix review comment * Mock websocket class * Replace the rest of the old websocket event tests * Improve websocket fixture for cleaner tests * Fix typing * Improve connection state signalling based on Martins feedback * Improve tests of reconnection_mechanisms based on Martins review comments * Fix unload entry * Fix isort issue after rebase * Fix martins comment on not using caplog * Fix wireless clients test * Fix martins comments on wireless clients test
35 lines
1 KiB
Python
35 lines
1 KiB
Python
"""Fixtures for UniFi methods."""
|
|
from typing import Optional
|
|
from unittest.mock import patch
|
|
|
|
from aiounifi.websocket import SIGNAL_CONNECTION_STATE, SIGNAL_DATA
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def mock_unifi_websocket():
|
|
"""No real websocket allowed."""
|
|
with patch("aiounifi.controller.WSClient") as mock:
|
|
|
|
def make_websocket_call(data: Optional[dict] = None, state: str = ""):
|
|
"""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
|
|
|
|
|
|
@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
|