<commit_before>"""The tests for the panel_iframe component."""
import unittest
from unittest.mock import patch

from homeassistant import setup
from homeassistant.components import frontend

from tests.common import get_test_home_assistant


class TestPanelIframe(unittest.TestCase):
    """Test the panel_iframe component."""

    def setup_method(self, method):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()

    def teardown_method(self, method):
        """Stop everything that was started."""
        self.hass.stop()

    def test_wrong_config(self):
        """Test setup with wrong configuration."""
        to_try = [
            {'invalid space': {
                'url': 'https://home-assistant.io'}},
            {'router': {
                'url': 'not-a-url'}}]

        for conf in to_try:
            assert not setup.setup_component(
                self.hass, 'panel_iframe', {
                    'panel_iframe': conf
                })

    @patch.dict('homeassistant.components.frontend.FINGERPRINTS', {
        'panels/ha-panel-iframe.html': 'md5md5'})
    def test_correct_config(self):
        """Test correct config."""
        assert setup.setup_component(
            self.hass, 'panel_iframe', {
                'panel_iframe': {
                    'router': {
                        'icon': 'mdi:network-wireless',
                        'title': 'Router',
                        'url': 'http://192.168.1.1',
                    },
                    'weather': {
                        'icon': 'mdi:weather',
                        'title': 'Weather',
                        'url': 'https://www.wunderground.com/us/ca/san-diego',
                    },
                },
            })

        # 5 dev tools + map are automatically loaded + 2 iframe panels
        assert len(self.hass.data[frontend.DATA_PANELS]) == 8
        assert self.hass.data[frontend.DATA_PANELS]['router'] == {
            'component_name': 'iframe',
            'config': {'url': 'http://192.168.1.1'},
            'icon': 'mdi:network-wireless',
            'title': 'Router',
            'url': '/frontend/panels/iframe-md5md5.html',
            'url_path': 'router'
        }

        assert self.hass.data[frontend.DATA_PANELS]['weather'] == {
            'component_name': 'iframe',
            'config': {'url': 'https://www.wunderground.com/us/ca/san-diego'},
            'icon': 'mdi:weather',
            'title': 'Weather',
            'url': '/frontend/panels/iframe-md5md5.html',
            'url_path': 'weather',
        }<commit_msg>Fix iFrame panel test<commit_after>"""The tests for the panel_iframe component."""
import unittest
from unittest.mock import patch

from homeassistant import setup
from homeassistant.components import frontend

from tests.common import get_test_home_assistant


class TestPanelIframe(unittest.TestCase):
    """Test the panel_iframe component."""

    def setup_method(self, method):
        """Setup things to be run when tests are started."""
        self.hass = get_test_home_assistant()

    def teardown_method(self, method):
        """Stop everything that was started."""
        self.hass.stop()

    def test_wrong_config(self):
        """Test setup with wrong configuration."""
        to_try = [
            {'invalid space': {
                'url': 'https://home-assistant.io'}},
            {'router': {
                'url': 'not-a-url'}}]

        for conf in to_try:
            assert not setup.setup_component(
                self.hass, 'panel_iframe', {
                    'panel_iframe': conf
                })

    @patch.dict('homeassistant.components.frontend.FINGERPRINTS', {
        'panels/ha-panel-iframe.html': 'md5md5'})
    def test_correct_config(self):
        """Test correct config."""
        assert setup.setup_component(
            self.hass, 'panel_iframe', {
                'panel_iframe': {
                    'router': {
                        'icon': 'mdi:network-wireless',
                        'title': 'Router',
                        'url': 'http://192.168.1.1',
                    },
                    'weather': {
                        'icon': 'mdi:weather',
                        'title': 'Weather',
                        'url': 'https://www.wunderground.com/us/ca/san-diego',
                    },
                },
            })

        assert self.hass.data[frontend.DATA_PANELS].get('router') == {
            'component_name': 'iframe',
            'config': {'url': 'http://192.168.1.1'},
            'icon': 'mdi:network-wireless',
            'title': 'Router',
            'url': '/frontend/panels/iframe-md5md5.html',
            'url_path': 'router'
        }

        assert self.hass.data[frontend.DATA_PANELS].get('weather') == {
            'component_name': 'iframe',
            'config': {'url': 'https://www.wunderground.com/us/ca/san-diego'},
            'icon': 'mdi:weather',
            'title': 'Weather',
            'url': '/frontend/panels/iframe-md5md5.html',
            'url_path': 'weather',
        }
{'fraction_non_alphanumeric': 0.14338593415156828, 'fraction_numerical': 0.009156438729787648, 'mean_word_length': 1.7192796610169492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2256088', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1437, 'n_words': 288}