-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move imports in wake_on_lan component (#28100)
* Move imports in wake_on_lan component * Fix tox tests
- Loading branch information
Showing
4 changed files
with
40 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,46 @@ | ||
"""Tests for Wake On LAN component.""" | ||
import asyncio | ||
from unittest import mock | ||
|
||
import pytest | ||
import voluptuous as vol | ||
|
||
from homeassistant.setup import async_setup_component | ||
from homeassistant.components import wake_on_lan | ||
from homeassistant.components.wake_on_lan import DOMAIN, SERVICE_SEND_MAGIC_PACKET | ||
from homeassistant.setup import async_setup_component | ||
|
||
|
||
@pytest.fixture | ||
def mock_wakeonlan(): | ||
"""Mock mock_wakeonlan.""" | ||
module = mock.MagicMock() | ||
with mock.patch.dict("sys.modules", {"wakeonlan": module}): | ||
yield module | ||
from tests.common import MockDependency | ||
|
||
|
||
@asyncio.coroutine | ||
def test_send_magic_packet(hass, caplog, mock_wakeonlan): | ||
async def test_send_magic_packet(hass): | ||
"""Test of send magic packet service call.""" | ||
mac = "aa:bb:cc:dd:ee:ff" | ||
bc_ip = "192.168.255.255" | ||
|
||
yield from async_setup_component(hass, DOMAIN, {}) | ||
|
||
yield from hass.services.async_call( | ||
DOMAIN, | ||
SERVICE_SEND_MAGIC_PACKET, | ||
{"mac": mac, "broadcast_address": bc_ip}, | ||
blocking=True, | ||
) | ||
assert len(mock_wakeonlan.mock_calls) == 1 | ||
assert mock_wakeonlan.mock_calls[-1][1][0] == mac | ||
assert mock_wakeonlan.mock_calls[-1][2]["ip_address"] == bc_ip | ||
|
||
with pytest.raises(vol.Invalid): | ||
yield from hass.services.async_call( | ||
with MockDependency("wakeonlan") as mocked_wakeonlan: | ||
mac = "aa:bb:cc:dd:ee:ff" | ||
bc_ip = "192.168.255.255" | ||
|
||
wake_on_lan.wakeonlan = mocked_wakeonlan | ||
|
||
await async_setup_component(hass, DOMAIN, {}) | ||
|
||
await hass.services.async_call( | ||
DOMAIN, | ||
SERVICE_SEND_MAGIC_PACKET, | ||
{"broadcast_address": bc_ip}, | ||
{"mac": mac, "broadcast_address": bc_ip}, | ||
blocking=True, | ||
) | ||
assert len(mock_wakeonlan.mock_calls) == 1 | ||
|
||
yield from hass.services.async_call( | ||
DOMAIN, SERVICE_SEND_MAGIC_PACKET, {"mac": mac}, blocking=True | ||
) | ||
assert len(mock_wakeonlan.mock_calls) == 2 | ||
assert mock_wakeonlan.mock_calls[-1][1][0] == mac | ||
assert not mock_wakeonlan.mock_calls[-1][2] | ||
assert len(mocked_wakeonlan.mock_calls) == 1 | ||
assert mocked_wakeonlan.mock_calls[-1][1][0] == mac | ||
assert mocked_wakeonlan.mock_calls[-1][2]["ip_address"] == bc_ip | ||
|
||
with pytest.raises(vol.Invalid): | ||
await hass.services.async_call( | ||
DOMAIN, | ||
SERVICE_SEND_MAGIC_PACKET, | ||
{"broadcast_address": bc_ip}, | ||
blocking=True, | ||
) | ||
assert len(mocked_wakeonlan.mock_calls) == 1 | ||
|
||
await hass.services.async_call( | ||
DOMAIN, SERVICE_SEND_MAGIC_PACKET, {"mac": mac}, blocking=True | ||
) | ||
assert len(mocked_wakeonlan.mock_calls) == 2 | ||
assert mocked_wakeonlan.mock_calls[-1][1][0] == mac | ||
assert not mocked_wakeonlan.mock_calls[-1][2] |