From 10054567deb8efc42eb0cd9b03ce85ca5a980d38 Mon Sep 17 00:00:00 2001 From: Ryan Kraus Date: Sun, 30 Aug 2015 04:24:24 -0400 Subject: [PATCH 1/5] Added test for conversation and introduction components. --- tests/components/test_conversation.py | 80 +++++++++++++++++++++++++++ tests/components/test_introduction.py | 26 +++++++++ 2 files changed, 106 insertions(+) create mode 100644 tests/components/test_conversation.py create mode 100644 tests/components/test_introduction.py diff --git a/tests/components/test_conversation.py b/tests/components/test_conversation.py new file mode 100644 index 00000000000..b8f87705a4f --- /dev/null +++ b/tests/components/test_conversation.py @@ -0,0 +1,80 @@ +""" +tests.components.test_conversation +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Tests Conversation component. +""" +# pylint: disable=too-many-public-methods,protected-access +import unittest + +import homeassistant.core as ha +import homeassistant.components as core_components +import homeassistant.components.conversation as conversation +import homeassistant.components.demo as demo +import homeassistant.components.light as light + +from common import get_test_home_assistant + + +class TestConversation(unittest.TestCase): + """ Test the conversation component. """ + + def setUp(self): # pylint: disable=invalid-name + """ Start up ha for testing """ + self.hass = get_test_home_assistant(3) + demo.setup(self.hass, {demo.DOMAIN: {}}) + core_components.setup(self.hass, {}) + + def tearDown(self): # pylint: disable=invalid-name + """ Stop down stuff we started. """ + self.hass.stop() + + def test_setup_and_good_requests(self): + """ Setup and perform good requests """ + self.assertTrue( + conversation.setup(self.hass, {conversation.DOMAIN: {}})) + + light.turn_on(self.hass, '{}.kitchen'.format(light.DOMAIN)) + + event_data = {conversation.ATTR_TEXT: 'turn kitchen off'} + self.hass.services.call( + conversation.DOMAIN, 'process', event_data, True) + + self.assertFalse( + light.is_on(self.hass, '{}.kitchen'.format(light.DOMAIN))) + + event_data = {conversation.ATTR_TEXT: 'turn kitchen on'} + self.hass.services.call( + conversation.DOMAIN, 'process', event_data, True) + + self.assertTrue( + light.is_on(self.hass, '{}.kitchen'.format(light.DOMAIN))) + + def test_setup_and_bad_request_format(self): + """ Setup and perform a badly formatted request """ + self.assertTrue( + conversation.setup(self.hass, {conversation.DOMAIN: {}})) + + event_data = {conversation.ATTR_TEXT: + 'what is the answer to the ultimate question of life, ' + + 'the universe and everything'} + self.assertTrue(self.hass.services.call( + conversation.DOMAIN, 'process', event_data, True)) + + def test_setup_and_bad_request_entity(self): + """ Setup and perform requests with bad entity id """ + self.assertTrue( + conversation.setup(self.hass, {conversation.DOMAIN: {}})) + + event_data = {conversation.ATTR_TEXT: 'turn something off'} + self.assertTrue(self.hass.services.call( + conversation.DOMAIN, 'process', event_data, True)) + + def test_setup_and_bad_request_command(self): + """ Setup and perform requests with bad command """ + self.assertTrue( + conversation.setup(self.hass, {conversation.DOMAIN: {}})) + + event_data = {conversation.ATTR_TEXT: 'turn kitchen over'} + self.assertTrue(self.hass.services.call( + conversation.DOMAIN, 'process', event_data, True)) diff --git a/tests/components/test_introduction.py b/tests/components/test_introduction.py new file mode 100644 index 00000000000..ed9e592096e --- /dev/null +++ b/tests/components/test_introduction.py @@ -0,0 +1,26 @@ +""" +tests.components.test_introduction +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Tests Introduction component. +""" +# pylint: disable=too-many-public-methods,protected-access +import unittest + +import homeassistant.core as ha +import homeassistant.components.introduction as introduction + + +class TestIntroduction(unittest.TestCase): + """ Test the introduction module. """ + + def setUp(self): # pylint: disable=invalid-name + self.hass = ha.HomeAssistant() + + def tearDown(self): # pylint: disable=invalid-name + """ Stop down stuff we started. """ + self.hass.stop() + + def test_setup(self): + """ Create introduction entity. """ + introduction.setup(self.hass) From 5ba5e0ffb180d6841649de1d86e1beb7a29961a3 Mon Sep 17 00:00:00 2001 From: Ryan Kraus Date: Sun, 30 Aug 2015 04:30:19 -0400 Subject: [PATCH 2/5] Added another conversation test. --- tests/components/test_conversation.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/components/test_conversation.py b/tests/components/test_conversation.py index b8f87705a4f..4358603a49b 100644 --- a/tests/components/test_conversation.py +++ b/tests/components/test_conversation.py @@ -78,3 +78,12 @@ class TestConversation(unittest.TestCase): event_data = {conversation.ATTR_TEXT: 'turn kitchen over'} self.assertTrue(self.hass.services.call( conversation.DOMAIN, 'process', event_data, True)) + + def test_setup_and_bad_request_notext(self): + """ Setup and perform requests with bad command with no text """ + self.assertTrue( + conversation.setup(self.hass, {conversation.DOMAIN: {}})) + + event_data = {} + self.assertTrue(self.hass.services.call( + conversation.DOMAIN, 'process', event_data, True)) From 364d85b6dfbf841520d4edc3cd55ddfbf105ee9f Mon Sep 17 00:00:00 2001 From: Ryan Kraus Date: Sun, 30 Aug 2015 04:51:49 -0400 Subject: [PATCH 3/5] Fixed remote tests. --- tests/test_remote.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/test_remote.py b/tests/test_remote.py index e5bfd71199f..b075f05be5d 100644 --- a/tests/test_remote.py +++ b/tests/test_remote.py @@ -51,6 +51,10 @@ def setUpModule(): # pylint: disable=invalid-name # Start slave slave = remote.HomeAssistant(master_api) + bootstrap.setup_component( + slave, http.DOMAIN, + {http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD, + http.CONF_SERVER_PORT: 8130}}) slave.start() From 7dd7d7a191766b841b07ffa6bd65aba62ab7bb5b Mon Sep 17 00:00:00 2001 From: Ryan Kraus Date: Sun, 30 Aug 2015 05:04:04 -0400 Subject: [PATCH 4/5] Restructured conversation tests. --- tests/components/test_conversation.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/tests/components/test_conversation.py b/tests/components/test_conversation.py index 4358603a49b..c03cb3c5ffe 100644 --- a/tests/components/test_conversation.py +++ b/tests/components/test_conversation.py @@ -29,8 +29,22 @@ class TestConversation(unittest.TestCase): """ Stop down stuff we started. """ self.hass.stop() - def test_setup_and_good_requests(self): - """ Setup and perform good requests """ + def test_setup_and_turn_on(self): + """ Setup and perform good turn on requests """ + self.assertTrue( + conversation.setup(self.hass, {conversation.DOMAIN: {}})) + + light.turn_off(self.hass, '{}.kitchen'.format(light.DOMAIN)) + + event_data = {conversation.ATTR_TEXT: 'turn kitchen on'} + self.hass.services.call( + conversation.DOMAIN, 'process', event_data, True) + + self.assertTrue( + light.is_on(self.hass, '{}.kitchen'.format(light.DOMAIN))) + + def test_setup_and_turn_off(self): + """ Setup and perform good turn off requests """ self.assertTrue( conversation.setup(self.hass, {conversation.DOMAIN: {}})) @@ -43,13 +57,6 @@ class TestConversation(unittest.TestCase): self.assertFalse( light.is_on(self.hass, '{}.kitchen'.format(light.DOMAIN))) - event_data = {conversation.ATTR_TEXT: 'turn kitchen on'} - self.hass.services.call( - conversation.DOMAIN, 'process', event_data, True) - - self.assertTrue( - light.is_on(self.hass, '{}.kitchen'.format(light.DOMAIN))) - def test_setup_and_bad_request_format(self): """ Setup and perform a badly formatted request """ self.assertTrue( From 881901f4d3225769d519f8221c79cc952a736aef Mon Sep 17 00:00:00 2001 From: Ryan Kraus Date: Mon, 31 Aug 2015 02:48:26 -0400 Subject: [PATCH 5/5] Removed bogus intro test. --- tests/components/test_introduction.py | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 tests/components/test_introduction.py diff --git a/tests/components/test_introduction.py b/tests/components/test_introduction.py deleted file mode 100644 index ed9e592096e..00000000000 --- a/tests/components/test_introduction.py +++ /dev/null @@ -1,26 +0,0 @@ -""" -tests.components.test_introduction -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Tests Introduction component. -""" -# pylint: disable=too-many-public-methods,protected-access -import unittest - -import homeassistant.core as ha -import homeassistant.components.introduction as introduction - - -class TestIntroduction(unittest.TestCase): - """ Test the introduction module. """ - - def setUp(self): # pylint: disable=invalid-name - self.hass = ha.HomeAssistant() - - def tearDown(self): # pylint: disable=invalid-name - """ Stop down stuff we started. """ - self.hass.stop() - - def test_setup(self): - """ Create introduction entity. """ - introduction.setup(self.hass)