desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Test request with a valid username.'
def test_valid_username_request(self):
request_json = {'invalid_key': 'my_device'} result = requests.post(BRIDGE_URL_BASE.format('/api'), data=json.dumps(request_json), timeout=5) self.assertEqual(result.status_code, 400)
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant() self.mock_publish = mock_mqtt_component(self.hass)
'Stop everything that was started.'
def tearDown(self):
self.hass.stop()
'Test the controlling state via topic.'
def test_controlling_state_via_topic(self):
assert setup_component(self.hass, lock.DOMAIN, {lock.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'state-topic', 'command_topic': 'command-topic', 'payload_lock': 'LOCK', 'payload_unlock': 'UNLOCK'}}) state = self.hass.states.get('lock.test') self.assertEqual(STATE_UNLOCKED, state.state) ...
'Test the sending MQTT commands in optimistic mode.'
def test_sending_mqtt_commands_and_optimistic(self):
assert setup_component(self.hass, lock.DOMAIN, {lock.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'command_topic': 'command-topic', 'payload_lock': 'LOCK', 'payload_unlock': 'UNLOCK', 'qos': 2}}) state = self.hass.states.get('lock.test') self.assertEqual(STATE_UNLOCKED, state.state) self.assertTrue(stat...
'Test the controlling state via topic and JSON message.'
def test_controlling_state_via_topic_and_json_message(self):
assert setup_component(self.hass, lock.DOMAIN, {lock.DOMAIN: {'platform': 'mqtt', 'name': 'test', 'state_topic': 'state-topic', 'command_topic': 'command-topic', 'payload_lock': 'LOCK', 'payload_unlock': 'UNLOCK', 'value_template': '{{ value_json.val }}'}}) state = self.hass.states.get('lock.test') se...
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant() self.assertTrue(setup_component(self.hass, lock.DOMAIN, {'lock': {'platform': 'demo'}}))
'Stop everything that was started.'
def tearDown(self):
self.hass.stop()
'Test if lock is locked.'
def test_is_locked(self):
self.assertTrue(lock.is_locked(self.hass, FRONT)) self.hass.states.is_state(FRONT, 'locked') self.assertFalse(lock.is_locked(self.hass, KITCHEN)) self.hass.states.is_state(KITCHEN, 'unlocked')
'Test the locking of a lock.'
def test_locking(self):
lock.lock(self.hass, KITCHEN) self.hass.block_till_done() self.assertTrue(lock.is_locked(self.hass, KITCHEN))
'Test the unlocking of a lock.'
def test_unlocking(self):
lock.unlock(self.hass, FRONT) self.hass.block_till_done() self.assertFalse(lock.is_locked(self.hass, FRONT))
'Setup things to be run when tests are started.'
def setup_method(self):
self.hass = get_test_home_assistant() self._base_url = 'https://tts.voicetech.yandex.net/generate?'
'Stop everything that was started.'
def teardown_method(self):
default_tts = self.hass.config.path(tts.DEFAULT_CACHE_DIR) if os.path.isdir(default_tts): shutil.rmtree(default_tts) self.hass.stop()
'Test setup component.'
def test_setup_component(self):
config = {tts.DOMAIN: {'platform': 'yandextts', 'api_key': '1234567xx'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config)
'Test setup component without api key.'
def test_setup_component_without_api_key(self):
config = {tts.DOMAIN: {'platform': 'yandextts'}} with assert_setup_component(0, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config)
'Test service call say.'
def test_service_say(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) url_param = {'text': 'HomeAssistant', 'lang': 'en-US', 'key': '1234567xx', 'speaker': 'zahar', 'format': 'mp3', 'emotion': 'neutral', 'speed': 1} aioclient_mock.get(self._base_url, status=200, content='test', params=url_param) config = {tts....
'Test service call say.'
def test_service_say_russian_config(self, aioclient_mock):
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='test', params=url_param) config = {tts....
'Test service call say.'
def test_service_say_russian_service(self, aioclient_mock):
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='test', params=url_param) config = {tts....
'Test service call say.'
def test_service_say_timeout(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) url_param = {'text': 'HomeAssistant', 'lang': 'en-US', 'key': '1234567xx', 'speaker': 'zahar', 'format': 'mp3', 'emotion': 'neutral', 'speed': 1} aioclient_mock.get(self._base_url, status=200, exc=asyncio.TimeoutError(), params=url_param) co...
'Test service call say.'
def test_service_say_http_error(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) url_param = {'text': 'HomeAssistant', 'lang': 'en-US', 'key': '1234567xx', 'speaker': 'zahar', 'format': 'mp3', 'emotion': 'neutral', 'speed': 1} aioclient_mock.get(self._base_url, status=403, content='test', params=url_param) config = {tts....
'Test service call say.'
def test_service_say_specifed_speaker(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) url_param = {'text': 'HomeAssistant', 'lang': 'en-US', 'key': '1234567xx', 'speaker': 'alyss', 'format': 'mp3', 'emotion': 'neutral', 'speed': 1} aioclient_mock.get(self._base_url, status=200, content='test', params=url_param) config = {tts....
'Test service call say.'
def test_service_say_specifed_emotion(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) url_param = {'text': 'HomeAssistant', 'lang': 'en-US', 'key': '1234567xx', 'speaker': 'zahar', 'format': 'mp3', 'emotion': 'evil', 'speed': 1} aioclient_mock.get(self._base_url, status=200, content='test', params=url_param) config = {tts.DOM...
'Test service call say.'
def test_service_say_specified_low_speed(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) url_param = {'text': 'HomeAssistant', 'lang': 'en-US', 'key': '1234567xx', 'speaker': 'zahar', 'format': 'mp3', 'emotion': 'neutral', 'speed': '0.1'} aioclient_mock.get(self._base_url, status=200, content='test', params=url_param) config = {...
'Test service call say.'
def test_service_say_specified_speed(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) url_param = {'text': 'HomeAssistant', 'lang': 'en-US', 'key': '1234567xx', 'speaker': 'zahar', 'format': 'mp3', 'emotion': 'neutral', 'speed': 2} aioclient_mock.get(self._base_url, status=200, content='test', params=url_param) config = {tts....
'Setup things to be run when tests are started.'
def setup_method(self):
self.hass = get_test_home_assistant() self.url = 'https://api.voicerss.org/' self.form_data = {'key': '1234567xx', 'hl': 'en-us', 'c': 'MP3', 'f': '8khz_8bit_mono', 'src': 'I person is on front of your door.'}
'Stop everything that was started.'
def teardown_method(self):
default_tts = self.hass.config.path(tts.DEFAULT_CACHE_DIR) if os.path.isdir(default_tts): shutil.rmtree(default_tts) self.hass.stop()
'Test setup component.'
def test_setup_component(self):
config = {tts.DOMAIN: {'platform': 'voicerss', 'api_key': '1234567xx'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config)
'Test setup component without api key.'
def test_setup_component_without_api_key(self):
config = {tts.DOMAIN: {'platform': 'voicerss'}} with assert_setup_component(0, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config)
'Test service call say.'
def test_service_say(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) aioclient_mock.post(self.url, data=self.form_data, status=200, content='test') config = {tts.DOMAIN: {'platform': 'voicerss', 'api_key': '1234567xx'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN,...
'Test service call say with german code in the config.'
def test_service_say_german_config(self, aioclient_mock):
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='test') config = {tts.DOMAIN: {'platform': 'voicerss', 'api_key': '1234567xx', 'language': 'de-de'}} with assert_setup_component(1, tts...
'Test service call say with german code in the service.'
def test_service_say_german_service(self, aioclient_mock):
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='test') config = {tts.DOMAIN: {'platform': 'voicerss', 'api_key': '1234567xx'}} with assert_setup_component(1, tts.DOMAIN): set...
'Test service call say with http response 400.'
def test_service_say_error(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) aioclient_mock.post(self.url, data=self.form_data, status=400, content='test') config = {tts.DOMAIN: {'platform': 'voicerss', 'api_key': '1234567xx'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN,...
'Test service call say with http timeout.'
def test_service_say_timeout(self, aioclient_mock):
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,...
'Test service call say with http error api message.'
def test_service_say_error_msg(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) aioclient_mock.post(self.url, data=self.form_data, status=200, content='The subscription does not support SSML!') config = {tts.DOMAIN: {'platform': 'voicerss', 'api_key': '1234567xx'}} with assert_setup_component(1, tts.DOMAI...
'Setup things to be run when tests are started.'
def setup_method(self):
self.hass = get_test_home_assistant() self.demo_provider = DemoProvider('en') self.default_tts_cache = self.hass.config.path(tts.DEFAULT_CACHE_DIR) setup_component(self.hass, http.DOMAIN, {http.DOMAIN: {http.CONF_SERVER_PORT: get_test_instance_port()}})
'Stop everything that was started.'
def teardown_method(self):
if os.path.isdir(self.default_tts_cache): shutil.rmtree(self.default_tts_cache) self.hass.stop()
'Setup the demo platform with defaults.'
def test_setup_component_demo(self):
config = {tts.DOMAIN: {'platform': 'demo'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config) assert self.hass.services.has_service(tts.DOMAIN, 'demo_say') assert self.hass.services.has_service(tts.DOMAIN, 'clear_cache')
'Setup the demo platform with defaults.'
@patch('os.mkdir', side_effect=OSError(2, 'No access')) def test_setup_component_demo_no_access_cache_folder(self, mock_mkdir):
config = {tts.DOMAIN: {'platform': 'demo'}} assert (not setup_component(self.hass, tts.DOMAIN, config)) assert (not self.hass.services.has_service(tts.DOMAIN, 'demo_say')) assert (not self.hass.services.has_service(tts.DOMAIN, 'clear_cache'))
'Setup the demo platform and call service.'
def test_setup_component_and_test_service(self):
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 fro...
'Setup the demo platform and call service.'
def test_setup_component_and_test_service_with_config_language(self):
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.services.call(tts.DOMAIN, 'demo_say', {tts.ATTR_MESSAGE: 'I person ...
'Setup the demo platform and call service with wrong config.'
def test_setup_component_and_test_service_with_wrong_conf_language(self):
config = {tts.DOMAIN: {'platform': 'demo', 'language': 'ru'}} with assert_setup_component(0, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config)
'Setup the demo platform and call service.'
def test_setup_component_and_test_service_with_service_language(self):
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 fro...
'Setup the demo platform and call service.'
def test_setup_component_test_service_with_wrong_service_language(self):
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 fro...
'Setup the demo platform and call service with options.'
def test_setup_component_and_test_service_with_service_options(self):
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 fro...
'Setup the demo platform and call service with default options.'
@patch('homeassistant.components.tts.demo.DemoProvider.default_options', new_callable=PropertyMock(return_value={'voice': 'alex'})) def test_setup_component_and_test_with_service_options_def(self, def_mock):
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 fro...
'Setup the demo platform and call service with wrong options.'
def test_setup_component_and_test_service_with_service_options_wrong(self):
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 fro...
'Setup the demo platform and call service clear cache.'
def test_setup_component_and_test_service_clear_cache(self):
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 fro...
'Setup the demo platform and call service and receive voice.'
def test_setup_component_and_test_service_with_receive_voice(self):
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 per...
'Setup the demo platform and call service and receive voice.'
def test_setup_component_and_test_service_with_receive_voice_german(self):
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_...
'Setup the demo platform and receive wrong file from web.'
def test_setup_component_and_web_view_wrong_file(self):
config = {tts.DOMAIN: {'platform': 'demo'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config) self.hass.start() url = '{}/api/tts_proxy/265944c108cbb00b2a621be5930513e03a0bb2cd_en_-_demo.mp3'.format(self.hass.config.api.base_url) req = requests.get(ur...
'Setup the demo platform and receive wrong filename from web.'
def test_setup_component_and_web_view_wrong_filename(self):
config = {tts.DOMAIN: {'platform': 'demo'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config) self.hass.start() url = '{}/api/tts_proxy/265944dsk32c1b2a621be5930510bb2cd_en_-_demo.mp3'.format(self.hass.config.api.base_url) req = requests.get(url) ...
'Setup demo platform without cache.'
def test_setup_component_test_without_cache(self):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) config = {tts.DOMAIN: {'platform': 'demo', 'cache': False}} 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 ...
'Setup demo platform with cache and call service without cache.'
def test_setup_component_test_with_cache_call_service_without_cache(self):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) config = {tts.DOMAIN: {'platform': 'demo', 'cache': True}} 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 ...
'Setup demo platform with cache and call service without cache.'
def test_setup_component_test_with_cache_dir(self):
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 vo...
'Setup demo platform with wrong get_tts_audio.'
@patch('homeassistant.components.tts.demo.DemoProvider.get_tts_audio', return_value=(None, None)) def test_setup_component_test_with_error_on_get_tts(self, tts_mock):
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 fro...
'Setup component and load cache and get without mem cache.'
def test_setup_component_load_cache_retrieve_without_mem_cache(self):
(_, 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.DOM...
'Setup things to be run when tests are started.'
def setup_method(self):
self.hass = get_test_home_assistant() self.url = 'http://localhost:59125/process?' self.url_param = {'INPUT_TEXT': 'HomeAssistant', 'INPUT_TYPE': 'TEXT', 'AUDIO': 'WAVE', 'VOICE': 'cmu-slt-hsmm', 'OUTPUT_TYPE': 'AUDIO', 'LOCALE': 'en_US'}
'Stop everything that was started.'
def teardown_method(self):
default_tts = self.hass.config.path(tts.DEFAULT_CACHE_DIR) if os.path.isdir(default_tts): shutil.rmtree(default_tts) self.hass.stop()
'Test setup component.'
def test_setup_component(self):
config = {tts.DOMAIN: {'platform': 'marytts'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config)
'Test service call say.'
def test_service_say(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) aioclient_mock.get(self.url, params=self.url_param, status=200, content='test') config = {tts.DOMAIN: {'platform': 'marytts'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config) self.hass.s...
'Test service call say.'
def test_service_say_timeout(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) aioclient_mock.get(self.url, params=self.url_param, status=200, exc=asyncio.TimeoutError()) config = {tts.DOMAIN: {'platform': 'marytts'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config) ...
'Test service call say.'
def test_service_say_http_error(self, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) aioclient_mock.get(self.url, params=self.url_param, status=403, content='test') config = {tts.DOMAIN: {'platform': 'marytts'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config) self.hass.s...
'Setup things to be run when tests are started.'
def setup_method(self):
self.hass = get_test_home_assistant() self.url = 'http://translate.google.com/translate_tts' self.url_param = {'tl': 'en', 'q': '90%25%20of%20I%20person%20is%20on%20front%20of%20your%20door.', 'tk': 5, 'client': 'tw-ob', 'textlen': 41, 'total': 1, 'idx': 0, 'ie': 'UTF-8'}
'Stop everything that was started.'
def teardown_method(self):
default_tts = self.hass.config.path(tts.DEFAULT_CACHE_DIR) if os.path.isdir(default_tts): shutil.rmtree(default_tts) self.hass.stop()
'Test setup component.'
def test_setup_component(self):
config = {tts.DOMAIN: {'platform': 'google'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config)
'Test service call say.'
@patch('gtts_token.gtts_token.Token.calculate_token', autospec=True, return_value=5) def test_service_say(self, mock_calculate, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) aioclient_mock.get(self.url, params=self.url_param, status=200, content='test') config = {tts.DOMAIN: {'platform': 'google'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config) self.hass.se...
'Test service call say with german code in the config.'
@patch('gtts_token.gtts_token.Token.calculate_token', autospec=True, return_value=5) def test_service_say_german_config(self, mock_calculate, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) self.url_param['tl'] = 'de' aioclient_mock.get(self.url, params=self.url_param, status=200, content='test') config = {tts.DOMAIN: {'platform': 'google', 'language': 'de'}} with assert_setup_component(1, tts.DOMAIN): setup_compone...
'Test service call say with german code in the service.'
@patch('gtts_token.gtts_token.Token.calculate_token', autospec=True, return_value=5) def test_service_say_german_service(self, mock_calculate, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) self.url_param['tl'] = 'de' aioclient_mock.get(self.url, params=self.url_param, status=200, content='test') config = {tts.DOMAIN: {'platform': 'google'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts....
'Test service call say with http response 400.'
@patch('gtts_token.gtts_token.Token.calculate_token', autospec=True, return_value=5) def test_service_say_error(self, mock_calculate, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) aioclient_mock.get(self.url, params=self.url_param, status=400, content='test') config = {tts.DOMAIN: {'platform': 'google'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config) self.hass.se...
'Test service call say with http timeout.'
@patch('gtts_token.gtts_token.Token.calculate_token', autospec=True, return_value=5) def test_service_say_timeout(self, mock_calculate, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) aioclient_mock.get(self.url, params=self.url_param, exc=asyncio.TimeoutError()) config = {tts.DOMAIN: {'platform': 'google'}} with assert_setup_component(1, tts.DOMAIN): setup_component(self.hass, tts.DOMAIN, config) self.hass.se...
'Test service call say with a lot of text.'
@patch('gtts_token.gtts_token.Token.calculate_token', autospec=True, return_value=5) def test_service_say_long_size(self, mock_calculate, aioclient_mock):
calls = mock_service(self.hass, DOMAIN_MP, SERVICE_PLAY_MEDIA) self.url_param['total'] = 9 self.url_param['q'] = 'I%20person%20is%20on%20front%20of%20your%20door' self.url_param['textlen'] = 33 for idx in range(0, 9): self.url_param['idx'] = idx aioclient_mock.get(self.url, params=se...
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant() self.log_filter = None
'Stop everything that was started.'
def tearDown(self):
del logging.root.handlers[(-1)] self.hass.stop()
'Setup logger and save log filter.'
def setup_logger(self, config):
setup_component(self.hass, logger.DOMAIN, config) self.log_filter = logging.root.handlers[(-1)].filters[0]
'Assert that a certain record was logged.'
def assert_logged(self, name, level):
self.assertTrue(self.log_filter.filter(RECORD(name, level)))
'Assert that a certain record was not logged.'
def assert_not_logged(self, name, level):
self.assertFalse(self.log_filter.filter(RECORD(name, level)))
'Use logger to create a logging filter.'
def test_logger_setup(self):
self.setup_logger(TEST_CONFIG) self.assertTrue((len(logging.root.handlers) > 0)) handler = logging.root.handlers[(-1)] self.assertEqual(len(handler.filters), 1) log_filter = handler.filters[0].logfilter self.assertEqual(log_filter['default'], logging.WARNING) self.assertEqual(log_filter['log...
'Test resulting filter operation.'
def test_logger_test_filters(self):
self.setup_logger(TEST_CONFIG) self.assert_not_logged('asdf', logging.DEBUG) self.assert_logged('asdf', logging.WARNING) self.assert_not_logged('test', logging.DEBUG) self.assert_logged('test', logging.INFO)
'Test change log level from empty configuration.'
def test_set_filter_empty_config(self):
self.setup_logger(NO_LOGS_CONFIG) self.assert_not_logged('test', logging.DEBUG) self.hass.services.call(logger.DOMAIN, 'set_level', {'test': 'debug'}) self.hass.block_till_done() self.assert_logged('test', logging.DEBUG)
'Test change log level of existing filter.'
def test_set_filter(self):
self.setup_logger(TEST_CONFIG) self.assert_not_logged('asdf', logging.DEBUG) self.assert_logged('dummy', logging.WARNING) self.hass.services.call(logger.DOMAIN, 'set_level', {'asdf': 'debug', 'dummy': 'info'}) self.hass.block_till_done() self.assert_logged('asdf', logging.DEBUG) self.assert_...
'Init pilight client, ignore parameters.'
def __init__(self, host, port):
pass
'Called pilight.send service is called.'
def send_code(self, call):
_LOGGER.error(('PilightDaemonSim payload: ' + str(call)))
'Called homeassistant.start is called. Also sends one test message after start up'
def start(self):
_LOGGER.error('PilightDaemonSim start') if (not self.called): self.callback(self.test_message) self.called = True
'Called homeassistant.stop is called.'
def stop(self):
_LOGGER.error('PilightDaemonSim stop')
'Callback called on event pilight.pilight_received.'
def set_callback(self, function):
self.callback = function _LOGGER.error(('PilightDaemonSim callback: ' + str(function)))
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant() self.skip_teardown_stop = False
'Stop everything that was started.'
def tearDown(self):
if (not self.skip_teardown_stop): self.hass.stop()
'Try to connect at 127.0.0.1:5000 with socket error.'
@patch('homeassistant.components.pilight._LOGGER.error') def test_connection_failed_error(self, mock_error):
with assert_setup_component(4): with patch('pilight.pilight.Client', side_effect=socket.error) as mock_client: self.assertFalse(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {}})) mock_client.assert_called_once_with(host=pilight.DEFAULT_HOST, port=pilight.DEFAULT_PORT) ...
'Try to connect at 127.0.0.1:5000 with socket timeout.'
@patch('homeassistant.components.pilight._LOGGER.error') def test_connection_timeout_error(self, mock_error):
with assert_setup_component(4): with patch('pilight.pilight.Client', side_effect=socket.timeout) as mock_client: self.assertFalse(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {}})) mock_client.assert_called_once_with(host=pilight.DEFAULT_HOST, port=pilight.DEFAULT_PORT...
'Try to send data without protocol information, should give error.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('homeassistant.core._LOGGER.error') @patch('tests.components.test_pilight._LOGGER.error') def test_send_code_no_protocol(self, mock_pilight_error, mock_error):
with assert_setup_component(4): self.assertTrue(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {}})) self.hass.services.call(pilight.DOMAIN, pilight.SERVICE_NAME, service_data={'noprotocol': 'test', 'value': 42}, blocking=True) self.hass.block_till_done() error_log_call ...
'Try to send proper data.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('tests.components.test_pilight._LOGGER.error') def test_send_code(self, mock_pilight_error):
with assert_setup_component(4): self.assertTrue(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {}})) service_data = {'protocol': 'test', 'value': 42} self.hass.services.call(pilight.DOMAIN, pilight.SERVICE_NAME, service_data=service_data, blocking=True) self.hass.block_t...
'Check IOError exception error message.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('homeassistant.components.pilight._LOGGER.error') def test_send_code_fail(self, mock_pilight_error):
with assert_setup_component(4): with patch('pilight.pilight.Client.send_code', side_effect=IOError): self.assertTrue(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {}})) service_data = {'protocol': 'test', 'value': 42} self.hass.services.call(pilight.DOMAIN, ...
'Try to send proper data with delay afterwards.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('tests.components.test_pilight._LOGGER.error') def test_send_code_delay(self, mock_pilight_error):
with assert_setup_component(4): self.assertTrue(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {pilight.CONF_SEND_DELAY: 5.0}})) service_data1 = {'protocol': 'test11', 'value': 42} service_data2 = {'protocol': 'test22', 'value': 42} self.hass.services.call(pilight.DOMAIN...
'Check correct startup and stop of pilight daemon.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('tests.components.test_pilight._LOGGER.error') def test_start_stop(self, mock_pilight_error):
with assert_setup_component(4): self.assertTrue(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {}})) self.hass.start() self.hass.block_till_done() error_log_call = mock_pilight_error.call_args_list[(-2)] self.assertTrue(('PilightDaemonSim callback' in str(erro...
'Check if code receiving via pilight daemon works.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('homeassistant.core._LOGGER.info') def test_receive_code(self, mock_info):
with assert_setup_component(4): self.assertTrue(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {}})) self.hass.start() self.hass.block_till_done() expected_message = dict({'protocol': PilightDaemonSim.test_message['protocol'], 'uuid': PilightDaemonSim.test_message['uuid'...
'Check whitelist filter with matched data.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('homeassistant.core._LOGGER.info') def test_whitelist_exact_match(self, mock_info):
with assert_setup_component(4): whitelist = {'protocol': [PilightDaemonSim.test_message['protocol']], 'uuid': [PilightDaemonSim.test_message['uuid']], 'id': [PilightDaemonSim.test_message['message']['id']], 'unit': [PilightDaemonSim.test_message['message']['unit']]} self.assertTrue(setup_component(s...
'Check whitelist filter with partially matched data, should work.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('homeassistant.core._LOGGER.info') def test_whitelist_partial_match(self, mock_info):
with assert_setup_component(4): whitelist = {'protocol': [PilightDaemonSim.test_message['protocol']], 'id': [PilightDaemonSim.test_message['message']['id']]} self.assertTrue(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {'whitelist': whitelist}})) self.hass.start() self...
'Check whitelist filter with several subsection, should work.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('homeassistant.core._LOGGER.info') def test_whitelist_or_match(self, mock_info):
with assert_setup_component(4): whitelist = {'protocol': [PilightDaemonSim.test_message['protocol'], 'other_protocoll'], 'id': [PilightDaemonSim.test_message['message']['id']]} self.assertTrue(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {'whitelist': whitelist}})) self.hass.s...
'Check whitelist filter with unmatched data, should not work.'
@patch('pilight.pilight.Client', PilightDaemonSim) @patch('homeassistant.core._LOGGER.info') def test_whitelist_no_match(self, mock_info):
with assert_setup_component(4): whitelist = {'protocol': ['wrong_protocoll'], 'id': [PilightDaemonSim.test_message['message']['id']]} self.assertTrue(setup_component(self.hass, pilight.DOMAIN, {pilight.DOMAIN: {'whitelist': whitelist}})) self.hass.start() self.hass.block_till_done() ...
'Setup things to be run when tests are started.'
def setUp(self):
self.hass = get_test_home_assistant()