mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Restructure tests to ensure unique ports
This commit is contained in:
parent
64430f26f3
commit
dd2aec0a08
@ -13,9 +13,11 @@ from homeassistant.helpers.entity import ToggleEntity
|
|||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME, EVENT_TIME_CHANGED,
|
STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME, EVENT_TIME_CHANGED,
|
||||||
EVENT_STATE_CHANGED, EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE,
|
EVENT_STATE_CHANGED, EVENT_PLATFORM_DISCOVERED, ATTR_SERVICE,
|
||||||
ATTR_DISCOVERED)
|
ATTR_DISCOVERED, SERVER_PORT)
|
||||||
from homeassistant.components import sun, mqtt
|
from homeassistant.components import sun, mqtt
|
||||||
|
|
||||||
|
_TEST_INSTANCE_PORT = SERVER_PORT
|
||||||
|
|
||||||
|
|
||||||
def get_test_config_dir():
|
def get_test_config_dir():
|
||||||
""" Returns a path to a test config dir. """
|
""" Returns a path to a test config dir. """
|
||||||
@ -43,6 +45,18 @@ def get_test_home_assistant(num_threads=None):
|
|||||||
return hass
|
return hass
|
||||||
|
|
||||||
|
|
||||||
|
def get_test_instance_port():
|
||||||
|
"""Return unused port for running test instance.
|
||||||
|
|
||||||
|
The socket that holds the default port does not get released when we stop
|
||||||
|
HA in a different test case. Until I have figured out what is going on,
|
||||||
|
let's run each test on a different port.
|
||||||
|
"""
|
||||||
|
global _TEST_INSTANCE_PORT
|
||||||
|
_TEST_INSTANCE_PORT += 1
|
||||||
|
return _TEST_INSTANCE_PORT
|
||||||
|
|
||||||
|
|
||||||
def mock_service(hass, domain, service):
|
def mock_service(hass, domain, service):
|
||||||
"""
|
"""
|
||||||
Sets up a fake service.
|
Sets up a fake service.
|
||||||
|
@ -13,9 +13,9 @@ from homeassistant import bootstrap, const
|
|||||||
import homeassistant.components.device_tracker as device_tracker
|
import homeassistant.components.device_tracker as device_tracker
|
||||||
import homeassistant.components.http as http
|
import homeassistant.components.http as http
|
||||||
|
|
||||||
from tests.common import get_test_home_assistant
|
from tests.common import get_test_home_assistant, get_test_instance_port
|
||||||
|
|
||||||
SERVER_PORT = 8126
|
SERVER_PORT = get_test_instance_port()
|
||||||
HTTP_BASE_URL = "http://127.0.0.1:{}".format(SERVER_PORT)
|
HTTP_BASE_URL = "http://127.0.0.1:{}".format(SERVER_PORT)
|
||||||
|
|
||||||
hass = None
|
hass = None
|
||||||
@ -128,7 +128,8 @@ class TestLocative(unittest.TestCase):
|
|||||||
# Enter the Home
|
# Enter the Home
|
||||||
req = requests.get(_url(data))
|
req = requests.get(_url(data))
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
state_name = hass.states.get('{}.{}'.format('device_tracker', data['device'])).state
|
state_name = hass.states.get('{}.{}'.format('device_tracker',
|
||||||
|
data['device'])).state
|
||||||
self.assertEqual(state_name, 'home')
|
self.assertEqual(state_name, 'home')
|
||||||
|
|
||||||
data['id'] = 'HOME'
|
data['id'] = 'HOME'
|
||||||
@ -137,7 +138,8 @@ class TestLocative(unittest.TestCase):
|
|||||||
# Exit Home
|
# Exit Home
|
||||||
req = requests.get(_url(data))
|
req = requests.get(_url(data))
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
state_name = hass.states.get('{}.{}'.format('device_tracker', data['device'])).state
|
state_name = hass.states.get('{}.{}'.format('device_tracker',
|
||||||
|
data['device'])).state
|
||||||
self.assertEqual(state_name, 'not_home')
|
self.assertEqual(state_name, 'not_home')
|
||||||
|
|
||||||
data['id'] = 'hOmE'
|
data['id'] = 'hOmE'
|
||||||
@ -146,7 +148,8 @@ class TestLocative(unittest.TestCase):
|
|||||||
# Enter Home again
|
# Enter Home again
|
||||||
req = requests.get(_url(data))
|
req = requests.get(_url(data))
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
state_name = hass.states.get('{}.{}'.format('device_tracker', data['device'])).state
|
state_name = hass.states.get('{}.{}'.format('device_tracker',
|
||||||
|
data['device'])).state
|
||||||
self.assertEqual(state_name, 'home')
|
self.assertEqual(state_name, 'home')
|
||||||
|
|
||||||
data['trigger'] = 'exit'
|
data['trigger'] = 'exit'
|
||||||
@ -154,7 +157,8 @@ class TestLocative(unittest.TestCase):
|
|||||||
# Exit Home
|
# Exit Home
|
||||||
req = requests.get(_url(data))
|
req = requests.get(_url(data))
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
state_name = hass.states.get('{}.{}'.format('device_tracker', data['device'])).state
|
state_name = hass.states.get('{}.{}'.format('device_tracker',
|
||||||
|
data['device'])).state
|
||||||
self.assertEqual(state_name, 'not_home')
|
self.assertEqual(state_name, 'not_home')
|
||||||
|
|
||||||
data['id'] = 'work'
|
data['id'] = 'work'
|
||||||
@ -163,7 +167,8 @@ class TestLocative(unittest.TestCase):
|
|||||||
# Enter Work
|
# Enter Work
|
||||||
req = requests.get(_url(data))
|
req = requests.get(_url(data))
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
state_name = hass.states.get('{}.{}'.format('device_tracker', data['device'])).state
|
state_name = hass.states.get('{}.{}'.format('device_tracker',
|
||||||
|
data['device'])).state
|
||||||
self.assertEqual(state_name, 'work')
|
self.assertEqual(state_name, 'work')
|
||||||
|
|
||||||
def test_exit_after_enter(self, update_config):
|
def test_exit_after_enter(self, update_config):
|
||||||
@ -181,7 +186,8 @@ class TestLocative(unittest.TestCase):
|
|||||||
req = requests.get(_url(data))
|
req = requests.get(_url(data))
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
|
|
||||||
state = hass.states.get('{}.{}'.format('device_tracker', data['device']))
|
state = hass.states.get('{}.{}'.format('device_tracker',
|
||||||
|
data['device']))
|
||||||
self.assertEqual(state.state, 'home')
|
self.assertEqual(state.state, 'home')
|
||||||
|
|
||||||
data['id'] = 'Work'
|
data['id'] = 'Work'
|
||||||
@ -190,7 +196,8 @@ class TestLocative(unittest.TestCase):
|
|||||||
req = requests.get(_url(data))
|
req = requests.get(_url(data))
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
|
|
||||||
state = hass.states.get('{}.{}'.format('device_tracker', data['device']))
|
state = hass.states.get('{}.{}'.format('device_tracker',
|
||||||
|
data['device']))
|
||||||
self.assertEqual(state.state, 'work')
|
self.assertEqual(state.state, 'work')
|
||||||
|
|
||||||
data['id'] = 'Home'
|
data['id'] = 'Home'
|
||||||
@ -200,7 +207,8 @@ class TestLocative(unittest.TestCase):
|
|||||||
req = requests.get(_url(data))
|
req = requests.get(_url(data))
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
|
|
||||||
state = hass.states.get('{}.{}'.format('device_tracker', data['device']))
|
state = hass.states.get('{}.{}'.format('device_tracker',
|
||||||
|
data['device']))
|
||||||
self.assertEqual(state.state, 'work')
|
self.assertEqual(state.state, 'work')
|
||||||
|
|
||||||
def test_exit_first(self, update_config):
|
def test_exit_first(self, update_config):
|
||||||
@ -218,5 +226,6 @@ class TestLocative(unittest.TestCase):
|
|||||||
req = requests.get(_url(data))
|
req = requests.get(_url(data))
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
|
|
||||||
state = hass.states.get('{}.{}'.format('device_tracker', data['device']))
|
state = hass.states.get('{}.{}'.format('device_tracker',
|
||||||
|
data['device']))
|
||||||
self.assertEqual(state.state, 'not_home')
|
self.assertEqual(state.state, 'not_home')
|
||||||
|
@ -15,17 +15,17 @@ from homeassistant import bootstrap, const
|
|||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.components import alexa, http
|
from homeassistant.components import alexa, http
|
||||||
|
|
||||||
|
from tests.common import get_test_instance_port
|
||||||
|
|
||||||
API_PASSWORD = "test1234"
|
API_PASSWORD = "test1234"
|
||||||
|
SERVER_PORT = get_test_instance_port()
|
||||||
# Somehow the socket that holds the default port does not get released
|
|
||||||
# when we close down HA in a different test case. Until I have figured
|
|
||||||
# out what is going on, let's run this test on a different port.
|
|
||||||
SERVER_PORT = 8119
|
|
||||||
|
|
||||||
API_URL = "http://127.0.0.1:{}{}".format(SERVER_PORT, alexa.API_ENDPOINT)
|
API_URL = "http://127.0.0.1:{}{}".format(SERVER_PORT, alexa.API_ENDPOINT)
|
||||||
|
|
||||||
HA_HEADERS = {const.HTTP_HEADER_HA_AUTH: API_PASSWORD}
|
HA_HEADERS = {const.HTTP_HEADER_HA_AUTH: API_PASSWORD}
|
||||||
|
|
||||||
|
SESSION_ID = 'amzn1.echo-api.session.0000000-0000-0000-0000-00000000000'
|
||||||
|
APPLICATION_ID = 'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe'
|
||||||
|
REQUEST_ID = 'amzn1.echo-api.request.0000000-0000-0000-0000-00000000000'
|
||||||
|
|
||||||
hass = None
|
hass = None
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
@ -53,10 +53,16 @@ def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
|
|||||||
'type': 'plaintext',
|
'type': 'plaintext',
|
||||||
'text':
|
'text':
|
||||||
"""
|
"""
|
||||||
{%- if is_state('device_tracker.paulus', 'home') and is_state('device_tracker.anne_therese', 'home') -%}
|
{%- if is_state('device_tracker.paulus', 'home')
|
||||||
|
and is_state('device_tracker.anne_therese',
|
||||||
|
'home') -%}
|
||||||
You are both home, you silly
|
You are both home, you silly
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
Anne Therese is at {{ states("device_tracker.anne_therese") }} and Paulus is at {{ states("device_tracker.paulus") }}
|
Anne Therese is at {{
|
||||||
|
states("device_tracker.anne_therese")
|
||||||
|
}} and Paulus is at {{
|
||||||
|
states("device_tracker.paulus")
|
||||||
|
}}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
""",
|
""",
|
||||||
}
|
}
|
||||||
@ -105,9 +111,9 @@ class TestAlexa(unittest.TestCase):
|
|||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'session': {
|
'session': {
|
||||||
'new': True,
|
'new': True,
|
||||||
'sessionId': 'amzn1.echo-api.session.0000000-0000-0000-0000-00000000000',
|
'sessionId': SESSION_ID,
|
||||||
'application': {
|
'application': {
|
||||||
'applicationId': 'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe'
|
'applicationId': APPLICATION_ID
|
||||||
},
|
},
|
||||||
'attributes': {},
|
'attributes': {},
|
||||||
'user': {
|
'user': {
|
||||||
@ -116,7 +122,7 @@ class TestAlexa(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
'request': {
|
'request': {
|
||||||
'type': 'LaunchRequest',
|
'type': 'LaunchRequest',
|
||||||
'requestId': 'amzn1.echo-api.request.0000000-0000-0000-0000-00000000000',
|
'requestId': REQUEST_ID,
|
||||||
'timestamp': '2015-05-13T12:34:56Z'
|
'timestamp': '2015-05-13T12:34:56Z'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,9 +136,9 @@ class TestAlexa(unittest.TestCase):
|
|||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'session': {
|
'session': {
|
||||||
'new': False,
|
'new': False,
|
||||||
'sessionId': 'amzn1.echo-api.session.0000000-0000-0000-0000-00000000000',
|
'sessionId': SESSION_ID,
|
||||||
'application': {
|
'application': {
|
||||||
'applicationId': 'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe'
|
'applicationId': APPLICATION_ID
|
||||||
},
|
},
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'supportedHoroscopePeriods': {
|
'supportedHoroscopePeriods': {
|
||||||
@ -147,7 +153,7 @@ class TestAlexa(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
'request': {
|
'request': {
|
||||||
'type': 'IntentRequest',
|
'type': 'IntentRequest',
|
||||||
'requestId': ' amzn1.echo-api.request.0000000-0000-0000-0000-00000000000',
|
'requestId': REQUEST_ID,
|
||||||
'timestamp': '2015-05-13T12:34:56Z',
|
'timestamp': '2015-05-13T12:34:56Z',
|
||||||
'intent': {
|
'intent': {
|
||||||
'name': 'GetZodiacHoroscopeIntent',
|
'name': 'GetZodiacHoroscopeIntent',
|
||||||
@ -162,7 +168,8 @@ class TestAlexa(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
req = _req(data)
|
req = _req(data)
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
text = req.json().get('response', {}).get('outputSpeech', {}).get('text')
|
text = req.json().get('response', {}).get('outputSpeech',
|
||||||
|
{}).get('text')
|
||||||
self.assertEqual('You told us your sign is virgo.', text)
|
self.assertEqual('You told us your sign is virgo.', text)
|
||||||
|
|
||||||
def test_intent_request_with_slots_but_no_value(self):
|
def test_intent_request_with_slots_but_no_value(self):
|
||||||
@ -170,9 +177,9 @@ class TestAlexa(unittest.TestCase):
|
|||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'session': {
|
'session': {
|
||||||
'new': False,
|
'new': False,
|
||||||
'sessionId': 'amzn1.echo-api.session.0000000-0000-0000-0000-00000000000',
|
'sessionId': SESSION_ID,
|
||||||
'application': {
|
'application': {
|
||||||
'applicationId': 'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe'
|
'applicationId': APPLICATION_ID
|
||||||
},
|
},
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'supportedHoroscopePeriods': {
|
'supportedHoroscopePeriods': {
|
||||||
@ -187,7 +194,7 @@ class TestAlexa(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
'request': {
|
'request': {
|
||||||
'type': 'IntentRequest',
|
'type': 'IntentRequest',
|
||||||
'requestId': ' amzn1.echo-api.request.0000000-0000-0000-0000-00000000000',
|
'requestId': REQUEST_ID,
|
||||||
'timestamp': '2015-05-13T12:34:56Z',
|
'timestamp': '2015-05-13T12:34:56Z',
|
||||||
'intent': {
|
'intent': {
|
||||||
'name': 'GetZodiacHoroscopeIntent',
|
'name': 'GetZodiacHoroscopeIntent',
|
||||||
@ -201,7 +208,8 @@ class TestAlexa(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
req = _req(data)
|
req = _req(data)
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
text = req.json().get('response', {}).get('outputSpeech', {}).get('text')
|
text = req.json().get('response', {}).get('outputSpeech',
|
||||||
|
{}).get('text')
|
||||||
self.assertEqual('You told us your sign is .', text)
|
self.assertEqual('You told us your sign is .', text)
|
||||||
|
|
||||||
def test_intent_request_without_slots(self):
|
def test_intent_request_without_slots(self):
|
||||||
@ -209,9 +217,9 @@ class TestAlexa(unittest.TestCase):
|
|||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'session': {
|
'session': {
|
||||||
'new': False,
|
'new': False,
|
||||||
'sessionId': 'amzn1.echo-api.session.0000000-0000-0000-0000-00000000000',
|
'sessionId': SESSION_ID,
|
||||||
'application': {
|
'application': {
|
||||||
'applicationId': 'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe'
|
'applicationId': APPLICATION_ID
|
||||||
},
|
},
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'supportedHoroscopePeriods': {
|
'supportedHoroscopePeriods': {
|
||||||
@ -226,7 +234,7 @@ class TestAlexa(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
'request': {
|
'request': {
|
||||||
'type': 'IntentRequest',
|
'type': 'IntentRequest',
|
||||||
'requestId': ' amzn1.echo-api.request.0000000-0000-0000-0000-00000000000',
|
'requestId': REQUEST_ID,
|
||||||
'timestamp': '2015-05-13T12:34:56Z',
|
'timestamp': '2015-05-13T12:34:56Z',
|
||||||
'intent': {
|
'intent': {
|
||||||
'name': 'WhereAreWeIntent',
|
'name': 'WhereAreWeIntent',
|
||||||
@ -235,16 +243,19 @@ class TestAlexa(unittest.TestCase):
|
|||||||
}
|
}
|
||||||
req = _req(data)
|
req = _req(data)
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
text = req.json().get('response', {}).get('outputSpeech', {}).get('text')
|
text = req.json().get('response', {}).get('outputSpeech',
|
||||||
|
{}).get('text')
|
||||||
|
|
||||||
self.assertEqual('Anne Therese is at unknown and Paulus is at unknown', text)
|
self.assertEqual('Anne Therese is at unknown and Paulus is at unknown',
|
||||||
|
text)
|
||||||
|
|
||||||
hass.states.set('device_tracker.paulus', 'home')
|
hass.states.set('device_tracker.paulus', 'home')
|
||||||
hass.states.set('device_tracker.anne_therese', 'home')
|
hass.states.set('device_tracker.anne_therese', 'home')
|
||||||
|
|
||||||
req = _req(data)
|
req = _req(data)
|
||||||
self.assertEqual(200, req.status_code)
|
self.assertEqual(200, req.status_code)
|
||||||
text = req.json().get('response', {}).get('outputSpeech', {}).get('text')
|
text = req.json().get('response', {}).get('outputSpeech',
|
||||||
|
{}).get('text')
|
||||||
self.assertEqual('You are both home, you silly', text)
|
self.assertEqual('You are both home, you silly', text)
|
||||||
|
|
||||||
def test_intent_request_calling_service(self):
|
def test_intent_request_calling_service(self):
|
||||||
@ -252,9 +263,9 @@ class TestAlexa(unittest.TestCase):
|
|||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'session': {
|
'session': {
|
||||||
'new': False,
|
'new': False,
|
||||||
'sessionId': 'amzn1.echo-api.session.0000000-0000-0000-0000-00000000000',
|
'sessionId': SESSION_ID,
|
||||||
'application': {
|
'application': {
|
||||||
'applicationId': 'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe'
|
'applicationId': APPLICATION_ID
|
||||||
},
|
},
|
||||||
'attributes': {},
|
'attributes': {},
|
||||||
'user': {
|
'user': {
|
||||||
@ -263,7 +274,7 @@ class TestAlexa(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
'request': {
|
'request': {
|
||||||
'type': 'IntentRequest',
|
'type': 'IntentRequest',
|
||||||
'requestId': ' amzn1.echo-api.request.0000000-0000-0000-0000-00000000000',
|
'requestId': REQUEST_ID,
|
||||||
'timestamp': '2015-05-13T12:34:56Z',
|
'timestamp': '2015-05-13T12:34:56Z',
|
||||||
'intent': {
|
'intent': {
|
||||||
'name': 'CallServiceIntent',
|
'name': 'CallServiceIntent',
|
||||||
@ -285,9 +296,9 @@ class TestAlexa(unittest.TestCase):
|
|||||||
'version': '1.0',
|
'version': '1.0',
|
||||||
'session': {
|
'session': {
|
||||||
'new': False,
|
'new': False,
|
||||||
'sessionId': 'amzn1.echo-api.session.0000000-0000-0000-0000-00000000000',
|
'sessionId': SESSION_ID,
|
||||||
'application': {
|
'application': {
|
||||||
'applicationId': 'amzn1.echo-sdk-ams.app.000000-d0ed-0000-ad00-000000d00ebe'
|
'applicationId': APPLICATION_ID
|
||||||
},
|
},
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'supportedHoroscopePeriods': {
|
'supportedHoroscopePeriods': {
|
||||||
@ -302,7 +313,7 @@ class TestAlexa(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
'request': {
|
'request': {
|
||||||
'type': 'SessionEndedRequest',
|
'type': 'SessionEndedRequest',
|
||||||
'requestId': 'amzn1.echo-api.request.0000000-0000-0000-0000-00000000000',
|
'requestId': REQUEST_ID,
|
||||||
'timestamp': '2015-05-13T12:34:56Z',
|
'timestamp': '2015-05-13T12:34:56Z',
|
||||||
'reason': 'USER_INITIATED'
|
'reason': 'USER_INITIATED'
|
||||||
}
|
}
|
||||||
|
@ -17,15 +17,11 @@ from homeassistant import bootstrap, const
|
|||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
import homeassistant.components.http as http
|
import homeassistant.components.http as http
|
||||||
|
|
||||||
|
from tests.common import get_test_instance_port
|
||||||
|
|
||||||
API_PASSWORD = "test1234"
|
API_PASSWORD = "test1234"
|
||||||
|
SERVER_PORT = get_test_instance_port()
|
||||||
# Somehow the socket that holds the default port does not get released
|
|
||||||
# when we close down HA in a different test case. Until I have figured
|
|
||||||
# out what is going on, let's run this test on a different port.
|
|
||||||
SERVER_PORT = 8120
|
|
||||||
|
|
||||||
HTTP_BASE_URL = "http://127.0.0.1:{}".format(SERVER_PORT)
|
HTTP_BASE_URL = "http://127.0.0.1:{}".format(SERVER_PORT)
|
||||||
|
|
||||||
HA_HEADERS = {const.HTTP_HEADER_HA_AUTH: API_PASSWORD}
|
HA_HEADERS = {const.HTTP_HEADER_HA_AUTH: API_PASSWORD}
|
||||||
|
|
||||||
hass = None
|
hass = None
|
||||||
@ -386,7 +382,7 @@ class TestAPI(unittest.TestCase):
|
|||||||
data=json.dumps({
|
data=json.dumps({
|
||||||
'api_password': 'bla-di-bla',
|
'api_password': 'bla-di-bla',
|
||||||
'host': '127.0.0.1',
|
'host': '127.0.0.1',
|
||||||
'port': '8125'
|
'port': get_test_instance_port()
|
||||||
}),
|
}),
|
||||||
headers=HA_HEADERS)
|
headers=HA_HEADERS)
|
||||||
self.assertEqual(422, req.status_code)
|
self.assertEqual(422, req.status_code)
|
||||||
|
@ -16,15 +16,11 @@ import homeassistant.bootstrap as bootstrap
|
|||||||
import homeassistant.components.http as http
|
import homeassistant.components.http as http
|
||||||
from homeassistant.const import HTTP_HEADER_HA_AUTH
|
from homeassistant.const import HTTP_HEADER_HA_AUTH
|
||||||
|
|
||||||
|
from tests.common import get_test_instance_port
|
||||||
|
|
||||||
API_PASSWORD = "test1234"
|
API_PASSWORD = "test1234"
|
||||||
|
SERVER_PORT = get_test_instance_port()
|
||||||
# Somehow the socket that holds the default port does not get released
|
|
||||||
# when we close down HA in a different test case. Until I have figured
|
|
||||||
# out what is going on, let's run this test on a different port.
|
|
||||||
SERVER_PORT = 8121
|
|
||||||
|
|
||||||
HTTP_BASE_URL = "http://127.0.0.1:{}".format(SERVER_PORT)
|
HTTP_BASE_URL = "http://127.0.0.1:{}".format(SERVER_PORT)
|
||||||
|
|
||||||
HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}
|
HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}
|
||||||
|
|
||||||
hass = None
|
hass = None
|
||||||
|
@ -6,7 +6,6 @@ Tests the group compoments.
|
|||||||
"""
|
"""
|
||||||
# pylint: disable=protected-access,too-many-public-methods
|
# pylint: disable=protected-access,too-many-public-methods
|
||||||
import unittest
|
import unittest
|
||||||
import logging
|
|
||||||
|
|
||||||
import homeassistant.core as ha
|
import homeassistant.core as ha
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -14,11 +13,6 @@ from homeassistant.const import (
|
|||||||
import homeassistant.components.group as group
|
import homeassistant.components.group as group
|
||||||
|
|
||||||
|
|
||||||
def setUpModule(): # pylint: disable=invalid-name
|
|
||||||
""" Setup to ignore group errors. """
|
|
||||||
logging.disable(logging.CRITICAL)
|
|
||||||
|
|
||||||
|
|
||||||
class TestComponentsGroup(unittest.TestCase):
|
class TestComponentsGroup(unittest.TestCase):
|
||||||
""" Tests homeassistant.components.group module. """
|
""" Tests homeassistant.components.group module. """
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ tests.remote
|
|||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
Tests Home Assistant remote methods and classes.
|
Tests Home Assistant remote methods and classes.
|
||||||
Uses port 8122 for master, 8123 for slave
|
|
||||||
Uses port 8125 as a port that nothing runs on
|
|
||||||
"""
|
"""
|
||||||
# pylint: disable=protected-access,too-many-public-methods
|
# pylint: disable=protected-access,too-many-public-methods
|
||||||
import unittest
|
import unittest
|
||||||
@ -16,9 +14,13 @@ import homeassistant.remote as remote
|
|||||||
import homeassistant.components.http as http
|
import homeassistant.components.http as http
|
||||||
from homeassistant.const import HTTP_HEADER_HA_AUTH
|
from homeassistant.const import HTTP_HEADER_HA_AUTH
|
||||||
|
|
||||||
API_PASSWORD = "test1234"
|
from tests.common import get_test_instance_port
|
||||||
|
|
||||||
HTTP_BASE_URL = "http://127.0.0.1:8122"
|
API_PASSWORD = "test1234"
|
||||||
|
MASTER_PORT = get_test_instance_port()
|
||||||
|
SLAVE_PORT = get_test_instance_port()
|
||||||
|
BROKEN_PORT = get_test_instance_port()
|
||||||
|
HTTP_BASE_URL = "http://127.0.0.1:{}".format(MASTER_PORT)
|
||||||
|
|
||||||
HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}
|
HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}
|
||||||
|
|
||||||
@ -44,25 +46,25 @@ def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name
|
|||||||
bootstrap.setup_component(
|
bootstrap.setup_component(
|
||||||
hass, http.DOMAIN,
|
hass, http.DOMAIN,
|
||||||
{http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
|
{http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
|
||||||
http.CONF_SERVER_PORT: 8122}})
|
http.CONF_SERVER_PORT: MASTER_PORT}})
|
||||||
|
|
||||||
bootstrap.setup_component(hass, 'api')
|
bootstrap.setup_component(hass, 'api')
|
||||||
|
|
||||||
hass.start()
|
hass.start()
|
||||||
|
|
||||||
master_api = remote.API("127.0.0.1", API_PASSWORD, 8122)
|
master_api = remote.API("127.0.0.1", API_PASSWORD, MASTER_PORT)
|
||||||
|
|
||||||
# Start slave
|
# Start slave
|
||||||
slave = remote.HomeAssistant(master_api)
|
slave = remote.HomeAssistant(master_api)
|
||||||
bootstrap.setup_component(
|
bootstrap.setup_component(
|
||||||
slave, http.DOMAIN,
|
slave, http.DOMAIN,
|
||||||
{http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
|
{http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
|
||||||
http.CONF_SERVER_PORT: 8130}})
|
http.CONF_SERVER_PORT: SLAVE_PORT}})
|
||||||
|
|
||||||
slave.start()
|
slave.start()
|
||||||
|
|
||||||
# Setup API pointing at nothing
|
# Setup API pointing at nothing
|
||||||
broken_api = remote.API("127.0.0.1", "", 8125)
|
broken_api = remote.API("127.0.0.1", "", BROKEN_PORT)
|
||||||
|
|
||||||
|
|
||||||
def tearDownModule(): # pylint: disable=invalid-name
|
def tearDownModule(): # pylint: disable=invalid-name
|
||||||
@ -83,7 +85,7 @@ class TestRemoteMethods(unittest.TestCase):
|
|||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
remote.APIStatus.INVALID_PASSWORD,
|
remote.APIStatus.INVALID_PASSWORD,
|
||||||
remote.validate_api(
|
remote.validate_api(
|
||||||
remote.API("127.0.0.1", API_PASSWORD + "A", 8122)))
|
remote.API("127.0.0.1", API_PASSWORD + "A", MASTER_PORT)))
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
remote.APIStatus.CANNOT_CONNECT, remote.validate_api(broken_api))
|
remote.APIStatus.CANNOT_CONNECT, remote.validate_api(broken_api))
|
||||||
@ -210,7 +212,7 @@ class TestRemoteClasses(unittest.TestCase):
|
|||||||
# Wrong port
|
# Wrong port
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
ha.HomeAssistantError, remote.HomeAssistant,
|
ha.HomeAssistantError, remote.HomeAssistant,
|
||||||
remote.API('127.0.0.1', API_PASSWORD, 8125))
|
remote.API('127.0.0.1', API_PASSWORD, BROKEN_PORT))
|
||||||
|
|
||||||
def test_statemachine_init(self):
|
def test_statemachine_init(self):
|
||||||
""" Tests if remote.StateMachine copies all states on init. """
|
""" Tests if remote.StateMachine copies all states on init. """
|
||||||
|
Loading…
x
Reference in New Issue
Block a user