Rewrite panel_iframe unittest tests to pytest style tests (#41368)
This commit is contained in:
parent
ca59c4a645
commit
5b0282e56d
1 changed files with 74 additions and 87 deletions
|
@ -1,41 +1,28 @@
|
||||||
"""The tests for the panel_iframe component."""
|
"""The tests for the panel_iframe component."""
|
||||||
import unittest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import setup
|
|
||||||
from homeassistant.components import frontend
|
from homeassistant.components import frontend
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
from tests.async_mock import patch
|
|
||||||
from tests.common import get_test_home_assistant
|
|
||||||
|
|
||||||
|
|
||||||
class TestPanelIframe(unittest.TestCase):
|
@pytest.mark.parametrize(
|
||||||
"""Test the panel_iframe component."""
|
"config_to_try",
|
||||||
|
(
|
||||||
def setUp(self):
|
|
||||||
"""Set up things to be run when tests are started."""
|
|
||||||
self.hass = get_test_home_assistant()
|
|
||||||
self.addCleanup(self.hass.stop)
|
|
||||||
|
|
||||||
def test_wrong_config(self):
|
|
||||||
"""Test setup with wrong configuration."""
|
|
||||||
to_try = [
|
|
||||||
{"invalid space": {"url": "https://home-assistant.io"}},
|
{"invalid space": {"url": "https://home-assistant.io"}},
|
||||||
{"router": {"url": "not-a-url"}},
|
{"router": {"url": "not-a-url"}},
|
||||||
]
|
),
|
||||||
|
)
|
||||||
for conf in to_try:
|
async def test_wrong_config(hass, config_to_try):
|
||||||
with patch(
|
"""Test setup with wrong configuration."""
|
||||||
"homeassistant.components.http.start_http_server_and_save_config"
|
assert not await async_setup_component(
|
||||||
):
|
hass, "panel_iframe", {"panel_iframe": config_to_try}
|
||||||
assert not setup.setup_component(
|
|
||||||
self.hass, "panel_iframe", {"panel_iframe": conf}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_correct_config(self):
|
|
||||||
|
async def test_correct_config(hass):
|
||||||
"""Test correct config."""
|
"""Test correct config."""
|
||||||
with patch("homeassistant.components.http.start_http_server_and_save_config"):
|
assert await async_setup_component(
|
||||||
assert setup.setup_component(
|
hass,
|
||||||
self.hass,
|
|
||||||
"panel_iframe",
|
"panel_iframe",
|
||||||
{
|
{
|
||||||
"panel_iframe": {
|
"panel_iframe": {
|
||||||
|
@ -61,7 +48,7 @@ class TestPanelIframe(unittest.TestCase):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
panels = self.hass.data[frontend.DATA_PANELS]
|
panels = hass.data[frontend.DATA_PANELS]
|
||||||
|
|
||||||
assert panels.get("router").to_response() == {
|
assert panels.get("router").to_response() == {
|
||||||
"component_name": "iframe",
|
"component_name": "iframe",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue