hass-core/tests/components/unifi/conftest.py
Christopher Bailey 5a72c9f7c3
Rename various usages of UniFi to better identify only UniFi Network ()
* Renames various usages of UniFi to better indentify only UniFi Network

* Apply suggestions from code review

Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>

* Missed renames

* Updates more locations

* Removes instances of application/controller

* Missed a spot

* Updates all UniFi Controller instances

* Fixes typo

* Reverts changes to translations

Co-authored-by: Robert Svensson <Kane610@users.noreply.github.com>
2021-11-26 22:44:49 +01:00

36 lines
1.1 KiB
Python

"""Fixtures for UniFi Network methods."""
from __future__ import annotations
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: dict | None = 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