• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python common.mock_service函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.common.mock_service函数的典型用法代码示例。如果您正苦于以下问题:Python mock_service函数的具体用法?Python mock_service怎么用?Python mock_service使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mock_service函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_methods

    def test_methods(self):
        """ Test if methods call the services as expected. """
        # Test is_on
        self.hass.states.set('light.test', STATE_ON)
        self.assertTrue(light.is_on(self.hass, 'light.test'))

        self.hass.states.set('light.test', STATE_OFF)
        self.assertFalse(light.is_on(self.hass, 'light.test'))

        self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_ON)
        self.assertTrue(light.is_on(self.hass))

        self.hass.states.set(light.ENTITY_ID_ALL_LIGHTS, STATE_OFF)
        self.assertFalse(light.is_on(self.hass))

        # Test turn_on
        turn_on_calls = mock_service(
            self.hass, light.DOMAIN, SERVICE_TURN_ON)

        light.turn_on(
            self.hass,
            entity_id='entity_id_val',
            transition='transition_val',
            brightness='brightness_val',
            rgb_color='rgb_color_val',
            xy_color='xy_color_val',
            profile='profile_val')

        self.hass.pool.block_till_done()

        self.assertEqual(1, len(turn_on_calls))
        call = turn_on_calls[-1]

        self.assertEqual(light.DOMAIN, call.domain)
        self.assertEqual(SERVICE_TURN_ON, call.service)
        self.assertEqual('entity_id_val', call.data.get(ATTR_ENTITY_ID))
        self.assertEqual(
            'transition_val', call.data.get(light.ATTR_TRANSITION))
        self.assertEqual(
            'brightness_val', call.data.get(light.ATTR_BRIGHTNESS))
        self.assertEqual('rgb_color_val', call.data.get(light.ATTR_RGB_COLOR))
        self.assertEqual('xy_color_val', call.data.get(light.ATTR_XY_COLOR))
        self.assertEqual('profile_val', call.data.get(light.ATTR_PROFILE))

        # Test turn_off
        turn_off_calls = mock_service(
            self.hass, light.DOMAIN, SERVICE_TURN_OFF)

        light.turn_off(
            self.hass, entity_id='entity_id_val', transition='transition_val')

        self.hass.pool.block_till_done()

        self.assertEqual(1, len(turn_off_calls))
        call = turn_off_calls[-1]

        self.assertEqual(light.DOMAIN, call.domain)
        self.assertEqual(SERVICE_TURN_OFF, call.service)
        self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
        self.assertEqual('transition_val', call.data[light.ATTR_TRANSITION])
开发者ID:michaelarnauts,项目名称:home-assistant,代码行数:60,代码来源:test_light.py


示例2: test_services

    def test_services(self):
        """Test the provided services."""

        # Test turn_on
        turn_on_calls = mock_service(
            self.hass, remote.DOMAIN, SERVICE_TURN_ON)

        remote.turn_on(
            self.hass,
            entity_id='entity_id_val')

        self.hass.block_till_done()

        self.assertEqual(1, len(turn_on_calls))
        call = turn_on_calls[-1]

        self.assertEqual(remote.DOMAIN, call.domain)

        # Test turn_off
        turn_off_calls = mock_service(
            self.hass, remote.DOMAIN, SERVICE_TURN_OFF)

        remote.turn_off(
            self.hass, entity_id='entity_id_val')

        self.hass.block_till_done()

        self.assertEqual(1, len(turn_off_calls))
        call = turn_off_calls[-1]

        self.assertEqual(remote.DOMAIN, call.domain)
        self.assertEqual(SERVICE_TURN_OFF, call.service)
        self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])

        # Test send_command
        send_command_calls = mock_service(
            self.hass, remote.DOMAIN, SERVICE_SEND_COMMAND)

        remote.send_command(
            self.hass, entity_id='entity_id_val',
            device='test_device', command='test_command')

        self.hass.block_till_done()

        self.assertEqual(1, len(send_command_calls))
        call = send_command_calls[-1]

        self.assertEqual(remote.DOMAIN, call.domain)
        self.assertEqual(SERVICE_SEND_COMMAND, call.service)
        self.assertEqual('entity_id_val', call.data[ATTR_ENTITY_ID])
开发者ID:DavidLP,项目名称:home-assistant,代码行数:50,代码来源:test_demo.py


示例3: test_if_fires_on_hass_start

def test_if_fires_on_hass_start(hass):
    """Test the firing when HASS starts."""
    calls = mock_service(hass, 'test', 'automation')
    hass.state = CoreState.not_running
    config = {
        automation.DOMAIN: {
            'alias': 'hello',
            'trigger': {
                'platform': 'homeassistant',
                'event': 'start',
            },
            'action': {
                'service': 'test.automation',
            }
        }
    }

    res = yield from async_setup_component(hass, automation.DOMAIN, config)
    assert res
    assert not automation.is_on(hass, 'automation.hello')
    assert len(calls) == 0

    yield from hass.async_start()
    assert automation.is_on(hass, 'automation.hello')
    assert len(calls) == 1

    with patch('homeassistant.config.async_hass_config_yaml',
               Mock(return_value=mock_coro(config))):
        yield from hass.services.async_call(
            automation.DOMAIN, automation.SERVICE_RELOAD, blocking=True)

    assert automation.is_on(hass, 'automation.hello')
    assert len(calls) == 1
开发者ID:azogue,项目名称:home-assistant,代码行数:33,代码来源:test_homeassistant.py


示例4: test_flux_before_sunrise

    def test_flux_before_sunrise(self):
        """Test the flux switch before sunrise."""
        platform = loader.get_component("light.test")
        platform.init()
        self.assertTrue(light.setup(self.hass, {light.DOMAIN: {CONF_PLATFORM: "test"}}))

        dev1 = platform.DEVICES[0]

        # Verify initial state of light
        state = self.hass.states.get(dev1.entity_id)
        self.assertEqual(STATE_ON, state.state)
        self.assertIsNone(state.attributes.get("xy_color"))
        self.assertIsNone(state.attributes.get("brightness"))

        test_time = dt_util.now().replace(hour=2, minute=30, second=0)
        sunset_time = test_time.replace(hour=17, minute=0, second=0)
        sunrise_time = test_time.replace(hour=5, minute=0, second=0) + timedelta(days=1)
        with patch("homeassistant.util.dt.now", return_value=test_time):
            with patch("homeassistant.components.sun.next_rising", return_value=sunrise_time):
                with patch("homeassistant.components.sun.next_setting", return_value=sunset_time):
                    assert setup_component(
                        self.hass,
                        switch.DOMAIN,
                        {switch.DOMAIN: {"platform": "flux", "name": "flux", "lights": [dev1.entity_id]}},
                    )
                    turn_on_calls = mock_service(self.hass, light.DOMAIN, SERVICE_TURN_ON)
                    switch.turn_on(self.hass, "switch.flux")
                    self.hass.pool.block_till_done()
                    fire_time_changed(self.hass, test_time)
                    self.hass.pool.block_till_done()
        call = turn_on_calls[-1]
        self.assertEqual(call.data[light.ATTR_BRIGHTNESS], 119)
        self.assertEqual(call.data[light.ATTR_XY_COLOR], [0.591, 0.395])
开发者ID:cellerich,项目名称:home-assistant,代码行数:33,代码来源:test_flux.py


示例5: test_if_fires_on_hass_shutdown

def test_if_fires_on_hass_shutdown(hass):
    """Test the firing when HASS starts."""
    calls = mock_service(hass, 'test', 'automation')
    hass.state = CoreState.not_running

    res = yield from async_setup_component(hass, automation.DOMAIN, {
        automation.DOMAIN: {
            'alias': 'hello',
            'trigger': {
                'platform': 'homeassistant',
                'event': 'shutdown',
            },
            'action': {
                'service': 'test.automation',
            }
        }
    })
    assert res
    assert not automation.is_on(hass, 'automation.hello')
    assert len(calls) == 0

    yield from hass.async_start()
    assert automation.is_on(hass, 'automation.hello')
    assert len(calls) == 0

    with patch.object(hass.loop, 'stop'):
        yield from hass.async_stop()
    assert len(calls) == 1
开发者ID:azogue,项目名称:home-assistant,代码行数:28,代码来源:test_homeassistant.py


示例6: test_service_say_german_config

    def test_service_say_german_config(self, aioclient_mock):
        """Test service call say with german code in the config."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        self.form_data['hl'] = 'de-de'
        aioclient_mock.post(
            self.url, data=self.form_data, status=200, content=b'test')

        config = {
            tts.DOMAIN: {
                'platform': 'voicerss',
                'api_key': '1234567xx',
                'language': 'de-de',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'voicerss_say', {
            tts.ATTR_MESSAGE: "I person is on front of your door.",
        })
        self.hass.block_till_done()

        assert len(calls) == 1
        assert len(aioclient_mock.mock_calls) == 1
        assert aioclient_mock.mock_calls[0][2] == self.form_data
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:27,代码来源:test_voicerss.py


示例7: test_automation_not_trigger_on_bootstrap

def test_automation_not_trigger_on_bootstrap(hass):
    """Test if automation is not trigger on bootstrap."""
    hass.state = CoreState.not_running
    calls = mock_service(hass, 'test', 'automation')

    res = yield from async_setup_component(hass, automation.DOMAIN, {
        automation.DOMAIN: {
            'alias': 'hello',
            'trigger': {
                'platform': 'event',
                'event_type': 'test_event',
            },
            'action': {
                'service': 'test.automation',
                'entity_id': 'hello.world'
            }
        }
    })
    assert res
    assert not automation.is_on(hass, 'automation.hello')

    hass.bus.async_fire('test_event')
    yield from hass.async_block_till_done()
    assert len(calls) == 0

    hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
    yield from hass.async_block_till_done()
    assert automation.is_on(hass, 'automation.hello')

    hass.bus.async_fire('test_event')
    yield from hass.async_block_till_done()

    assert len(calls) == 1
    assert ['hello.world'] == calls[0].data.get(ATTR_ENTITY_ID)
开发者ID:ozzpy,项目名称:home-assistant,代码行数:34,代码来源:test_init.py


示例8: test_service_say_russian_config

    def test_service_say_russian_config(self, aioclient_mock):
        """Test service call say."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        url = "https://tts.voicetech.yandex.net/generate?format=mp3" \
              "&speaker=zahar&key=1234567xx&text=HomeAssistant&lang=ru-RU"
        aioclient_mock.get(
            url, status=200, content=b'test')

        config = {
            tts.DOMAIN: {
                'platform': 'yandextts',
                'api_key': '1234567xx',
                'language': 'ru-RU',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'yandextts_say', {
            tts.ATTR_MESSAGE: "HomeAssistant",
        })
        self.hass.block_till_done()

        assert len(aioclient_mock.mock_calls) == 1
        assert len(calls) == 1
开发者ID:thejacko12354,项目名称:home-assistant,代码行数:27,代码来源:test_yandextts.py


示例9: test_setup_component_test_with_cache_dir

    def test_setup_component_test_with_cache_dir(self):
        """Set up demo platform with cache and call service without cache."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        _, demo_data = self.demo_provider.get_tts_audio("bla", 'en')
        cache_file = os.path.join(
            self.default_tts_cache,
            "265944c108cbb00b2a621be5930513e03a0bb2cd_en_-_demo.mp3")

        os.mkdir(self.default_tts_cache)
        with open(cache_file, "wb") as voice_file:
            voice_file.write(demo_data)

        config = {
            tts.DOMAIN: {
                'platform': 'demo',
                'cache': True,
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        with patch('homeassistant.components.tts.demo.DemoProvider.'
                   'get_tts_audio', return_value=(None, None)):
            self.hass.services.call(tts.DOMAIN, 'demo_say', {
                tts.ATTR_MESSAGE: "I person is on front of your door.",
            })
        self.hass.block_till_done()

        assert len(calls) == 1
        assert calls[0].data[ATTR_MEDIA_CONTENT_ID] == \
            "{}/api/tts_proxy/265944c108cbb00b2a621be5930513e03a0bb2cd" \
            "_en_-_demo.mp3".format(self.hass.config.api.base_url)
开发者ID:arsaboo,项目名称:home-assistant,代码行数:34,代码来源:test_init.py


示例10: test_setup_component_and_test_service_clear_cache

    def test_setup_component_and_test_service_clear_cache(self):
        """Set up the demo platform and call service clear cache."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        config = {
            tts.DOMAIN: {
                'platform': 'demo',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'demo_say', {
            tts.ATTR_MESSAGE: "I person is on front of your door.",
        })
        self.hass.block_till_done()

        assert len(calls) == 1
        assert os.path.isfile(os.path.join(
            self.default_tts_cache,
            "265944c108cbb00b2a621be5930513e03a0bb2cd_en_-_demo.mp3"))

        self.hass.services.call(tts.DOMAIN, tts.SERVICE_CLEAR_CACHE, {})
        self.hass.block_till_done()

        assert not os.path.isfile(os.path.join(
            self.default_tts_cache,
            "265944c108cbb00b2a621be5930513e03a0bb2cd_en_-_demo.mp3"))
开发者ID:arsaboo,项目名称:home-assistant,代码行数:29,代码来源:test_init.py


示例11: test_setup_component_and_test_service_with_receive_voice_german

    def test_setup_component_and_test_service_with_receive_voice_german(self):
        """Set up the demo platform and call service and receive voice."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        config = {
            tts.DOMAIN: {
                'platform': 'demo',
                'language': 'de',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.start()

        self.hass.services.call(tts.DOMAIN, 'demo_say', {
            tts.ATTR_MESSAGE: "I person is on front of your door.",
        })
        self.hass.block_till_done()

        assert len(calls) == 1
        req = requests.get(calls[0].data[ATTR_MEDIA_CONTENT_ID])
        _, demo_data = self.demo_provider.get_tts_audio("bla", "de")
        demo_data = tts.SpeechManager.write_tags(
            "265944c108cbb00b2a621be5930513e03a0bb2cd_de_-_demo.mp3",
            demo_data, self.demo_provider,
            "I person is on front of your door.", 'de', None)
        assert req.status_code == 200
        assert req.content == demo_data
开发者ID:arsaboo,项目名称:home-assistant,代码行数:30,代码来源:test_init.py


示例12: test_setup_component_and_test_service_with_service_options_wrong

    def test_setup_component_and_test_service_with_service_options_wrong(self):
        """Set up the demo platform and call service with wrong options."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        config = {
            tts.DOMAIN: {
                'platform': 'demo',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'demo_say', {
            tts.ATTR_MESSAGE: "I person is on front of your door.",
            tts.ATTR_LANGUAGE: "de",
            tts.ATTR_OPTIONS: {
                'speed': 1
            }
        })
        self.hass.block_till_done()

        opt_hash = ctypes.c_size_t(hash(frozenset({'speed': 1}))).value

        assert len(calls) == 0
        assert not os.path.isfile(os.path.join(
            self.default_tts_cache,
            "265944c108cbb00b2a621be5930513e03a0bb2cd_de_{0}_demo.mp3".format(
                opt_hash)))
开发者ID:arsaboo,项目名称:home-assistant,代码行数:29,代码来源:test_init.py


示例13: test_setup_component_and_test_service_with_base_url_set

    def test_setup_component_and_test_service_with_base_url_set(self):
        """Set up the demo platform with ``base_url`` set and call service."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        config = {
            tts.DOMAIN: {
                'platform': 'demo',
                'base_url': 'http://fnord',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'demo_say', {
            tts.ATTR_MESSAGE: "I person is on front of your door.",
        })
        self.hass.block_till_done()

        assert len(calls) == 1
        assert calls[0].data[ATTR_MEDIA_CONTENT_TYPE] == MEDIA_TYPE_MUSIC
        assert calls[0].data[ATTR_MEDIA_CONTENT_ID] == \
            "http://fnord" \
            "/api/tts_proxy/265944c108cbb00b2a621be5930513e03a0bb2cd" \
            "_en_-_demo.mp3"
开发者ID:arsaboo,项目名称:home-assistant,代码行数:25,代码来源:test_init.py


示例14: test_setup_component_and_test_service_with_receive_voice_german

    def test_setup_component_and_test_service_with_receive_voice_german(self):
        """Setup the demo platform and call service and receive voice."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        config = {
            tts.DOMAIN: {
                'platform': 'demo',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.start()

        self.hass.services.call(tts.DOMAIN, 'demo_say', {
            tts.ATTR_MESSAGE: "I person is on front of your door.",
        })
        self.hass.block_till_done()

        assert len(calls) == 1
        req = requests.get(calls[0].data[ATTR_MEDIA_CONTENT_ID])
        _, demo_data = self.demo_provider.get_tts_audio("bla", "de")
        assert req.status_code == 200
        assert req.content == demo_data
开发者ID:Teagan42,项目名称:home-assistant,代码行数:25,代码来源:test_init.py


示例15: test_flux_when_switch_is_off

    def test_flux_when_switch_is_off(self):
        """Test the flux switch when it is off."""
        platform = loader.get_component("light.test")
        platform.init()
        self.assertTrue(light.setup(self.hass, {light.DOMAIN: {CONF_PLATFORM: "test"}}))

        dev1 = platform.DEVICES[0]

        # Verify initial state of light
        state = self.hass.states.get(dev1.entity_id)
        self.assertEqual(STATE_ON, state.state)
        self.assertIsNone(state.attributes.get("xy_color"))
        self.assertIsNone(state.attributes.get("brightness"))

        test_time = dt_util.now().replace(hour=10, minute=30, second=0)
        sunset_time = test_time.replace(hour=17, minute=0, second=0)
        sunrise_time = test_time.replace(hour=5, minute=0, second=0) + timedelta(days=1)
        with patch("homeassistant.util.dt.now", return_value=test_time):
            with patch("homeassistant.components.sun.next_rising", return_value=sunrise_time):
                with patch("homeassistant.components.sun.next_setting", return_value=sunset_time):
                    assert setup_component(
                        self.hass,
                        switch.DOMAIN,
                        {switch.DOMAIN: {"platform": "flux", "name": "flux", "lights": [dev1.entity_id]}},
                    )
                    turn_on_calls = mock_service(self.hass, light.DOMAIN, SERVICE_TURN_ON)
                    fire_time_changed(self.hass, test_time)
                    self.hass.pool.block_till_done()
        self.assertEqual(0, len(turn_on_calls))
开发者ID:cellerich,项目名称:home-assistant,代码行数:29,代码来源:test_flux.py


示例16: test_no_initial_value_and_restore_off

def test_no_initial_value_and_restore_off(hass):
    """Test initial value off and restored state is turned on."""
    calls = mock_service(hass, 'test', 'automation')
    mock_restore_cache(hass, (
        State('automation.hello', STATE_OFF),
    ))

    res = yield from async_setup_component(hass, automation.DOMAIN, {
        automation.DOMAIN: {
            'alias': 'hello',
            'trigger': {
                'platform': 'event',
                'event_type': 'test_event',
            },
            'action': {
                'service': 'test.automation',
                'entity_id': 'hello.world'
            }
        }
    })
    assert res
    assert not automation.is_on(hass, 'automation.hello')

    hass.bus.async_fire('test_event')
    yield from hass.async_block_till_done()
    assert len(calls) == 0
开发者ID:ozzpy,项目名称:home-assistant,代码行数:26,代码来源:test_init.py


示例17: test_service_say

    def test_service_say(self, aioclient_mock):
        """Test service call say."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        aioclient_mock.post(
            self.url, data=self.form_data, status=200, content=b'test')

        config = {
            tts.DOMAIN: {
                'platform': 'voicerss',
                'api_key': '1234567xx',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'voicerss_say', {
            tts.ATTR_MESSAGE: "I person is on front of your door.",
        })
        self.hass.block_till_done()

        assert len(calls) == 1
        assert len(aioclient_mock.mock_calls) == 1
        assert aioclient_mock.mock_calls[0][2] == self.form_data
        assert calls[0].data[ATTR_MEDIA_CONTENT_ID].find(".mp3") != -1
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:26,代码来源:test_voicerss.py


示例18: test_service_say_russian_config

    def test_service_say_russian_config(self, aioclient_mock):
        """Test service call say."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        url_param = {
            'text': 'HomeAssistant',
            'lang': 'ru-RU',
            'key': '1234567xx',
            'speaker': 'zahar',
            'format': 'mp3',
            'emotion': 'neutral',
            'speed': 1
        }
        aioclient_mock.get(
            self._base_url, status=200, content=b'test', params=url_param)

        config = {
            tts.DOMAIN: {
                'platform': 'yandextts',
                'api_key': '1234567xx',
                'language': 'ru-RU',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'yandextts_say', {
            tts.ATTR_MESSAGE: "HomeAssistant",
        })
        self.hass.block_till_done()

        assert len(aioclient_mock.mock_calls) == 1
        assert len(calls) == 1
开发者ID:Teagan42,项目名称:home-assistant,代码行数:34,代码来源:test_yandextts.py


示例19: test_service_say_error_msg

    def test_service_say_error_msg(self, aioclient_mock):
        """Test service call say with http error api message."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        aioclient_mock.post(
            self.url, data=self.form_data, status=200,
            content=b'The subscription does not support SSML!'
        )

        config = {
            tts.DOMAIN: {
                'platform': 'voicerss',
                'api_key': '1234567xx',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'voicerss_say', {
            tts.ATTR_MESSAGE: "I person is on front of your door.",
        })
        self.hass.block_till_done()

        assert len(calls) == 0
        assert len(aioclient_mock.mock_calls) == 1
        assert aioclient_mock.mock_calls[0][2] == self.form_data
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:27,代码来源:test_voicerss.py


示例20: test_service_say_timeout

    def test_service_say_timeout(self, aioclient_mock):
        """Test service call say with http timeout."""
        calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA)

        aioclient_mock.post(
            self.url, data=self.form_data, exc=asyncio.TimeoutError())

        config = {
            tts.DOMAIN: {
                'platform': 'voicerss',
                'api_key': '1234567xx',
            }
        }

        with assert_setup_component(1, tts.DOMAIN):
            setup_component(self.hass, tts.DOMAIN, config)

        self.hass.services.call(tts.DOMAIN, 'voicerss_say', {
            tts.ATTR_MESSAGE: "I person is on front of your door.",
        })
        self.hass.block_till_done()

        assert len(calls) == 0
        assert len(aioclient_mock.mock_calls) == 1
        assert aioclient_mock.mock_calls[0][2] == self.form_data
开发者ID:BaptisteSim,项目名称:home-assistant,代码行数:25,代码来源:test_voicerss.py



注:本文中的tests.common.mock_service函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python common.mock_state_change_event函数代码示例发布时间:2022-05-27
下一篇:
Python common.mock_restore_cache函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap