Test fixes (#22911)
* Fix light tests [skip ci] * Fix tests/common * Fix some mqtt tests [skip ci] * Fix tests and component manifests which have only one platform * Fix more tests and manifests * Fix demo/notify tests * Rollback test for demo.geo_location
This commit is contained in:
parent
1a05f7b04d
commit
590eead128
20 changed files with 68 additions and 48 deletions
|
@ -3,6 +3,6 @@
|
||||||
"name": "Ffmpeg motion",
|
"name": "Ffmpeg motion",
|
||||||
"documentation": "https://www.home-assistant.io/components/ffmpeg_motion",
|
"documentation": "https://www.home-assistant.io/components/ffmpeg_motion",
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
"dependencies": [],
|
"dependencies": ["ffmpeg"],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
"name": "Ffmpeg noise",
|
"name": "Ffmpeg noise",
|
||||||
"documentation": "https://www.home-assistant.io/components/ffmpeg_noise",
|
"documentation": "https://www.home-assistant.io/components/ffmpeg_noise",
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
"dependencies": [],
|
"dependencies": ["ffmpeg"],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"pywebpush==1.9.2"
|
"pywebpush==1.9.2"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": ["frontend"],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
"@robbiet480"
|
"@robbiet480"
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
"name": "Meraki",
|
"name": "Meraki",
|
||||||
"documentation": "https://www.home-assistant.io/components/meraki",
|
"documentation": "https://www.home-assistant.io/components/meraki",
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
"dependencies": [],
|
"dependencies": ["http"],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
"name": "Microsoft face detect",
|
"name": "Microsoft face detect",
|
||||||
"documentation": "https://www.home-assistant.io/components/microsoft_face_detect",
|
"documentation": "https://www.home-assistant.io/components/microsoft_face_detect",
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
"dependencies": [],
|
"dependencies": ["microsoft_face"],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
"name": "Microsoft face identify",
|
"name": "Microsoft face identify",
|
||||||
"documentation": "https://www.home-assistant.io/components/microsoft_face_identify",
|
"documentation": "https://www.home-assistant.io/components/microsoft_face_identify",
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
"dependencies": [],
|
"dependencies": ["microsoft_face"],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Push",
|
"name": "Push",
|
||||||
"documentation": "https://www.home-assistant.io/components/push",
|
"documentation": "https://www.home-assistant.io/components/push",
|
||||||
"requirements": [],
|
"requirements": [],
|
||||||
"dependencies": [],
|
"dependencies": ["webhook"],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
"@dgomes"
|
"@dgomes"
|
||||||
]
|
]
|
||||||
|
|
|
@ -244,7 +244,7 @@ def async_fire_mqtt_message(hass, topic, payload, qos=0, retain=False):
|
||||||
if isinstance(payload, str):
|
if isinstance(payload, str):
|
||||||
payload = payload.encode('utf-8')
|
payload = payload.encode('utf-8')
|
||||||
msg = mqtt.Message(topic, payload, qos, retain)
|
msg = mqtt.Message(topic, payload, qos, retain)
|
||||||
hass.async_run_job(hass.data['mqtt']._mqtt_on_message, None, None, msg)
|
hass.data['mqtt']._mqtt_handle_message(msg)
|
||||||
|
|
||||||
|
|
||||||
fire_mqtt_message = threadsafe_callback_factory(async_fire_mqtt_message)
|
fire_mqtt_message = threadsafe_callback_factory(async_fire_mqtt_message)
|
||||||
|
@ -287,8 +287,7 @@ def mock_state_change_event(hass, new_state, old_state=None):
|
||||||
hass.bus.fire(EVENT_STATE_CHANGED, event_data, context=new_state.context)
|
hass.bus.fire(EVENT_STATE_CHANGED, event_data, context=new_state.context)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_mock_mqtt_component(hass, config=None):
|
||||||
def async_mock_mqtt_component(hass, config=None):
|
|
||||||
"""Mock the MQTT component."""
|
"""Mock the MQTT component."""
|
||||||
if config is None:
|
if config is None:
|
||||||
config = {mqtt.CONF_BROKER: 'mock-broker'}
|
config = {mqtt.CONF_BROKER: 'mock-broker'}
|
||||||
|
@ -299,10 +298,11 @@ def async_mock_mqtt_component(hass, config=None):
|
||||||
mock_client().unsubscribe.return_value = (0, 0)
|
mock_client().unsubscribe.return_value = (0, 0)
|
||||||
mock_client().publish.return_value = (0, 0)
|
mock_client().publish.return_value = (0, 0)
|
||||||
|
|
||||||
result = yield from async_setup_component(hass, mqtt.DOMAIN, {
|
result = await async_setup_component(hass, mqtt.DOMAIN, {
|
||||||
mqtt.DOMAIN: config
|
mqtt.DOMAIN: config
|
||||||
})
|
})
|
||||||
assert result
|
assert result
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
hass.data['mqtt'] = MagicMock(spec_set=hass.data['mqtt'],
|
hass.data['mqtt'] = MagicMock(spec_set=hass.data['mqtt'],
|
||||||
wraps=hass.data['mqtt'])
|
wraps=hass.data['mqtt'])
|
||||||
|
@ -708,7 +708,7 @@ def assert_setup_component(count, domain=None):
|
||||||
yield config
|
yield config
|
||||||
|
|
||||||
if domain is None:
|
if domain is None:
|
||||||
assert len(config) == 1, ('assert_setup_component requires DOMAIN: {}'
|
assert len(config) >= 1, ('assert_setup_component requires DOMAIN: {}'
|
||||||
.format(list(config.keys())))
|
.format(list(config.keys())))
|
||||||
domain = list(config.keys())[0]
|
domain = list(config.keys())[0]
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,12 @@ class TestDemoPlatform(unittest.TestCase):
|
||||||
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
||||||
with assert_setup_component(1, geo_location.DOMAIN):
|
with assert_setup_component(1, geo_location.DOMAIN):
|
||||||
assert setup_component(self.hass, geo_location.DOMAIN, CONFIG)
|
assert setup_component(self.hass, geo_location.DOMAIN, CONFIG)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
# In this test, only entities of the geolocation domain have been
|
# In this test, five geolocation entities have been
|
||||||
# generated.
|
# generated.
|
||||||
all_states = self.hass.states.all()
|
all_states = self.hass.states.all()
|
||||||
|
print(all_states)
|
||||||
assert len(all_states) == NUMBER_OF_DEMO_DEVICES
|
assert len(all_states) == NUMBER_OF_DEMO_DEVICES
|
||||||
|
|
||||||
# Check a single device's attributes.
|
# Check a single device's attributes.
|
||||||
|
|
|
@ -45,6 +45,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||||
with assert_setup_component(1) as config:
|
with assert_setup_component(1) as config:
|
||||||
assert setup_component(self.hass, notify.DOMAIN, CONFIG)
|
assert setup_component(self.hass, notify.DOMAIN, CONFIG)
|
||||||
assert config[notify.DOMAIN]
|
assert config[notify.DOMAIN]
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
def test_setup(self):
|
def test_setup(self):
|
||||||
"""Test setup."""
|
"""Test setup."""
|
||||||
|
|
|
@ -29,6 +29,7 @@ class TestFFmpegNoiseSetup:
|
||||||
"""Set up ffmpeg component."""
|
"""Set up ffmpeg component."""
|
||||||
with assert_setup_component(1, 'binary_sensor'):
|
with assert_setup_component(1, 'binary_sensor'):
|
||||||
setup_component(self.hass, 'binary_sensor', self.config)
|
setup_component(self.hass, 'binary_sensor', self.config)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||||
assert self.hass.states.get('binary_sensor.ffmpeg_noise') is not None
|
assert self.hass.states.get('binary_sensor.ffmpeg_noise') is not None
|
||||||
|
@ -39,6 +40,7 @@ class TestFFmpegNoiseSetup:
|
||||||
"""Set up ffmpeg component."""
|
"""Set up ffmpeg component."""
|
||||||
with assert_setup_component(1, 'binary_sensor'):
|
with assert_setup_component(1, 'binary_sensor'):
|
||||||
setup_component(self.hass, 'binary_sensor', self.config)
|
setup_component(self.hass, 'binary_sensor', self.config)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||||
assert self.hass.states.get('binary_sensor.ffmpeg_noise') is not None
|
assert self.hass.states.get('binary_sensor.ffmpeg_noise') is not None
|
||||||
|
@ -54,6 +56,7 @@ class TestFFmpegNoiseSetup:
|
||||||
"""Set up ffmpeg component."""
|
"""Set up ffmpeg component."""
|
||||||
with assert_setup_component(1, 'binary_sensor'):
|
with assert_setup_component(1, 'binary_sensor'):
|
||||||
setup_component(self.hass, 'binary_sensor', self.config)
|
setup_component(self.hass, 'binary_sensor', self.config)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||||
assert self.hass.states.get('binary_sensor.ffmpeg_noise') is not None
|
assert self.hass.states.get('binary_sensor.ffmpeg_noise') is not None
|
||||||
|
@ -92,6 +95,7 @@ class TestFFmpegMotionSetup:
|
||||||
"""Set up ffmpeg component."""
|
"""Set up ffmpeg component."""
|
||||||
with assert_setup_component(1, 'binary_sensor'):
|
with assert_setup_component(1, 'binary_sensor'):
|
||||||
setup_component(self.hass, 'binary_sensor', self.config)
|
setup_component(self.hass, 'binary_sensor', self.config)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||||
assert self.hass.states.get('binary_sensor.ffmpeg_motion') is not None
|
assert self.hass.states.get('binary_sensor.ffmpeg_motion') is not None
|
||||||
|
@ -102,6 +106,7 @@ class TestFFmpegMotionSetup:
|
||||||
"""Set up ffmpeg component."""
|
"""Set up ffmpeg component."""
|
||||||
with assert_setup_component(1, 'binary_sensor'):
|
with assert_setup_component(1, 'binary_sensor'):
|
||||||
setup_component(self.hass, 'binary_sensor', self.config)
|
setup_component(self.hass, 'binary_sensor', self.config)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||||
assert self.hass.states.get('binary_sensor.ffmpeg_motion') is not None
|
assert self.hass.states.get('binary_sensor.ffmpeg_motion') is not None
|
||||||
|
@ -117,6 +122,7 @@ class TestFFmpegMotionSetup:
|
||||||
"""Set up ffmpeg component."""
|
"""Set up ffmpeg component."""
|
||||||
with assert_setup_component(1, 'binary_sensor'):
|
with assert_setup_component(1, 'binary_sensor'):
|
||||||
setup_component(self.hass, 'binary_sensor', self.config)
|
setup_component(self.hass, 'binary_sensor', self.config)
|
||||||
|
self.hass.block_till_done()
|
||||||
|
|
||||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||||
assert self.hass.states.get('binary_sensor.ffmpeg_motion') is not None
|
assert self.hass.states.get('binary_sensor.ffmpeg_motion') is not None
|
||||||
|
|
|
@ -113,34 +113,34 @@ def mock_dev_track(mock_device_tracker_conf):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def geofency_client(loop, hass, aiohttp_client):
|
async def geofency_client(loop, hass, aiohttp_client):
|
||||||
"""Geofency mock client (unauthenticated)."""
|
"""Geofency mock client (unauthenticated)."""
|
||||||
assert loop.run_until_complete(async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, 'persistent_notification', {}))
|
hass, 'persistent_notification', {})
|
||||||
|
|
||||||
assert loop.run_until_complete(async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, DOMAIN, {
|
hass, DOMAIN, {
|
||||||
DOMAIN: {
|
DOMAIN: {
|
||||||
CONF_MOBILE_BEACONS: ['Car 1']
|
CONF_MOBILE_BEACONS: ['Car 1']
|
||||||
}}))
|
}})
|
||||||
|
await hass.async_block_till_done()
|
||||||
loop.run_until_complete(hass.async_block_till_done())
|
|
||||||
|
|
||||||
with patch('homeassistant.components.device_tracker.update_config'):
|
with patch('homeassistant.components.device_tracker.update_config'):
|
||||||
yield loop.run_until_complete(aiohttp_client(hass.http.app))
|
return await aiohttp_client(hass.http.app)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def setup_zones(loop, hass):
|
async def setup_zones(loop, hass):
|
||||||
"""Set up Zone config in HA."""
|
"""Set up Zone config in HA."""
|
||||||
assert loop.run_until_complete(async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, zone.DOMAIN, {
|
hass, zone.DOMAIN, {
|
||||||
'zone': {
|
'zone': {
|
||||||
'name': 'Home',
|
'name': 'Home',
|
||||||
'latitude': HOME_LATITUDE,
|
'latitude': HOME_LATITUDE,
|
||||||
'longitude': HOME_LONGITUDE,
|
'longitude': HOME_LONGITUDE,
|
||||||
'radius': 100,
|
'radius': 100,
|
||||||
}}))
|
}})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -156,6 +156,7 @@ async def webhook_id(hass, geofency_client):
|
||||||
result['flow_id'], {})
|
result['flow_id'], {})
|
||||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
return result['result'].data['webhook_id']
|
return result['result'].data['webhook_id']
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,31 +26,34 @@ def mock_dev_track(mock_device_tracker_conf):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def gpslogger_client(loop, hass, aiohttp_client):
|
async def gpslogger_client(loop, hass, aiohttp_client):
|
||||||
"""Mock client for GPSLogger (unauthenticated)."""
|
"""Mock client for GPSLogger (unauthenticated)."""
|
||||||
assert loop.run_until_complete(async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, 'persistent_notification', {}))
|
hass, 'persistent_notification', {})
|
||||||
|
|
||||||
assert loop.run_until_complete(async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, DOMAIN, {
|
hass, DOMAIN, {
|
||||||
DOMAIN: {}
|
DOMAIN: {}
|
||||||
}))
|
})
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
with patch('homeassistant.components.device_tracker.update_config'):
|
with patch('homeassistant.components.device_tracker.update_config'):
|
||||||
yield loop.run_until_complete(aiohttp_client(hass.http.app))
|
return await aiohttp_client(hass.http.app)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def setup_zones(loop, hass):
|
async def setup_zones(loop, hass):
|
||||||
"""Set up Zone config in HA."""
|
"""Set up Zone config in HA."""
|
||||||
assert loop.run_until_complete(async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, zone.DOMAIN, {
|
hass, zone.DOMAIN, {
|
||||||
'zone': {
|
'zone': {
|
||||||
'name': 'Home',
|
'name': 'Home',
|
||||||
'latitude': HOME_LATITUDE,
|
'latitude': HOME_LATITUDE,
|
||||||
'longitude': HOME_LONGITUDE,
|
'longitude': HOME_LONGITUDE,
|
||||||
'radius': 100,
|
'radius': 100,
|
||||||
}}))
|
}})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -66,6 +69,7 @@ async def webhook_id(hass, gpslogger_client):
|
||||||
result['flow_id'], {})
|
result['flow_id'], {})
|
||||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
return result['result'].data['webhook_id']
|
return result['result'].data['webhook_id']
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ async def mock_client(hass, hass_client, registrations=None):
|
||||||
'platform': 'html5'
|
'platform': 'html5'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
return await hass_client()
|
return await hass_client()
|
||||||
|
|
||||||
|
|
|
@ -374,10 +374,10 @@ class TestLight(unittest.TestCase):
|
||||||
return True
|
return True
|
||||||
return real_isfile(path)
|
return real_isfile(path)
|
||||||
|
|
||||||
def _mock_open(path):
|
def _mock_open(path, *args, **kwargs):
|
||||||
if path == user_light_file:
|
if path == user_light_file:
|
||||||
return StringIO(profile_data)
|
return StringIO(profile_data)
|
||||||
return real_open(path)
|
return real_open(path, *args, **kwargs)
|
||||||
|
|
||||||
profile_data = "id,x,y,brightness\n" +\
|
profile_data = "id,x,y,brightness\n" +\
|
||||||
"group.all_lights.default,.4,.6,99\n"
|
"group.all_lights.default,.4,.6,99\n"
|
||||||
|
@ -412,10 +412,10 @@ class TestLight(unittest.TestCase):
|
||||||
return True
|
return True
|
||||||
return real_isfile(path)
|
return real_isfile(path)
|
||||||
|
|
||||||
def _mock_open(path):
|
def _mock_open(path, *args, **kwargs):
|
||||||
if path == user_light_file:
|
if path == user_light_file:
|
||||||
return StringIO(profile_data)
|
return StringIO(profile_data)
|
||||||
return real_open(path)
|
return real_open(path, *args, **kwargs)
|
||||||
|
|
||||||
profile_data = "id,x,y,brightness\n" +\
|
profile_data = "id,x,y,brightness\n" +\
|
||||||
"group.all_lights.default,.3,.5,200\n" +\
|
"group.all_lights.default,.3,.5,200\n" +\
|
||||||
|
|
|
@ -22,15 +22,16 @@ def mock_dev_track(mock_device_tracker_conf):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def locative_client(loop, hass, hass_client):
|
async def locative_client(loop, hass, hass_client):
|
||||||
"""Locative mock client."""
|
"""Locative mock client."""
|
||||||
assert loop.run_until_complete(async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, DOMAIN, {
|
hass, DOMAIN, {
|
||||||
DOMAIN: {}
|
DOMAIN: {}
|
||||||
}))
|
})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
with patch('homeassistant.components.device_tracker.update_config'):
|
with patch('homeassistant.components.device_tracker.update_config'):
|
||||||
yield loop.run_until_complete(hass_client())
|
return await hass_client()
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -45,6 +46,7 @@ async def webhook_id(hass, locative_client):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result['flow_id'], {})
|
result['flow_id'], {})
|
||||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
return result['result'].data['webhook_id']
|
return result['result'].data['webhook_id']
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ async def test_manual_config_set(hass, mock_try_connection,
|
||||||
"""Test we ignore entry if manual config available."""
|
"""Test we ignore entry if manual config available."""
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass, 'mqtt', {'mqtt': {'broker': 'bla'}})
|
hass, 'mqtt', {'mqtt': {'broker': 'bla'}})
|
||||||
|
await hass.async_block_till_done()
|
||||||
assert len(mock_finish_setup.mock_calls) == 1
|
assert len(mock_finish_setup.mock_calls) == 1
|
||||||
|
|
||||||
mock_try_connection.return_value = True
|
mock_try_connection.return_value = True
|
||||||
|
|
|
@ -28,8 +28,7 @@ def mock_MQTT():
|
||||||
yield mock_MQTT
|
yield mock_MQTT
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def async_mock_mqtt_client(hass, config=None):
|
||||||
def async_mock_mqtt_client(hass, config=None):
|
|
||||||
"""Mock the MQTT paho client."""
|
"""Mock the MQTT paho client."""
|
||||||
if config is None:
|
if config is None:
|
||||||
config = {mqtt.CONF_BROKER: 'mock-broker'}
|
config = {mqtt.CONF_BROKER: 'mock-broker'}
|
||||||
|
@ -39,10 +38,11 @@ def async_mock_mqtt_client(hass, config=None):
|
||||||
mock_client().subscribe.return_value = (0, 0)
|
mock_client().subscribe.return_value = (0, 0)
|
||||||
mock_client().unsubscribe.return_value = (0, 0)
|
mock_client().unsubscribe.return_value = (0, 0)
|
||||||
mock_client().publish.return_value = (0, 0)
|
mock_client().publish.return_value = (0, 0)
|
||||||
result = yield from async_setup_component(hass, mqtt.DOMAIN, {
|
result = await async_setup_component(hass, mqtt.DOMAIN, {
|
||||||
mqtt.DOMAIN: config
|
mqtt.DOMAIN: config
|
||||||
})
|
})
|
||||||
assert result
|
assert result
|
||||||
|
await hass.async_block_till_done()
|
||||||
return mock_client()
|
return mock_client()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,8 @@ class TestMQTT:
|
||||||
assert setup_component(self.hass, mqtt.DOMAIN, {
|
assert setup_component(self.hass, mqtt.DOMAIN, {
|
||||||
mqtt.DOMAIN: {CONF_PASSWORD: password},
|
mqtt.DOMAIN: {CONF_PASSWORD: password},
|
||||||
})
|
})
|
||||||
|
self.hass.block_till_done()
|
||||||
assert mock_mqtt.called
|
assert mock_mqtt.called
|
||||||
from pprint import pprint
|
|
||||||
pprint(mock_mqtt.mock_calls)
|
|
||||||
assert mock_mqtt.mock_calls[1][2]['username'] == 'homeassistant'
|
assert mock_mqtt.mock_calls[1][2]['username'] == 'homeassistant'
|
||||||
assert mock_mqtt.mock_calls[1][2]['password'] == password
|
assert mock_mqtt.mock_calls[1][2]['password'] == password
|
||||||
|
|
||||||
|
@ -61,9 +60,8 @@ class TestMQTT:
|
||||||
'http': {'api_password': 'http_secret'},
|
'http': {'api_password': 'http_secret'},
|
||||||
mqtt.DOMAIN: {CONF_PASSWORD: password},
|
mqtt.DOMAIN: {CONF_PASSWORD: password},
|
||||||
})
|
})
|
||||||
|
self.hass.block_till_done()
|
||||||
assert mock_mqtt.called
|
assert mock_mqtt.called
|
||||||
from pprint import pprint
|
|
||||||
pprint(mock_mqtt.mock_calls)
|
|
||||||
assert mock_mqtt.mock_calls[1][2]['username'] == 'homeassistant'
|
assert mock_mqtt.mock_calls[1][2]['username'] == 'homeassistant'
|
||||||
assert mock_mqtt.mock_calls[1][2]['password'] == password
|
assert mock_mqtt.mock_calls[1][2]['password'] == password
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ async def test_config_yaml_host_not_imported(hass):
|
||||||
'host': 'mock-host'
|
'host': 'mock-host'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(mock_init.mock_calls) == 0
|
assert len(mock_init.mock_calls) == 0
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ async def test_config_yaml_host_imported(hass):
|
||||||
'host': 'mock-host'
|
'host': 'mock-host'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
progress = hass.config_entries.flow.async_progress()
|
progress = hass.config_entries.flow.async_progress()
|
||||||
assert len(progress) == 1
|
assert len(progress) == 1
|
||||||
|
@ -54,6 +56,7 @@ async def test_config_json_host_not_imported(hass):
|
||||||
assert await async_setup_component(hass, 'tradfri', {
|
assert await async_setup_component(hass, 'tradfri', {
|
||||||
'tradfri': {}
|
'tradfri': {}
|
||||||
})
|
})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(mock_init.mock_calls) == 0
|
assert len(mock_init.mock_calls) == 0
|
||||||
|
|
||||||
|
@ -65,6 +68,7 @@ async def test_config_json_host_imported(hass, mock_gateway_info):
|
||||||
assert await async_setup_component(hass, 'tradfri', {
|
assert await async_setup_component(hass, 'tradfri', {
|
||||||
'tradfri': {}
|
'tradfri': {}
|
||||||
})
|
})
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
progress = hass.config_entries.flow.async_progress()
|
progress = hass.config_entries.flow.async_progress()
|
||||||
assert len(progress) == 1
|
assert len(progress) == 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue