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_locationpull/22929/head
parent
1a05f7b04d
commit
590eead128
|
@ -3,6 +3,6 @@
|
|||
"name": "Ffmpeg motion",
|
||||
"documentation": "https://www.home-assistant.io/components/ffmpeg_motion",
|
||||
"requirements": [],
|
||||
"dependencies": [],
|
||||
"dependencies": ["ffmpeg"],
|
||||
"codeowners": []
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
"name": "Ffmpeg noise",
|
||||
"documentation": "https://www.home-assistant.io/components/ffmpeg_noise",
|
||||
"requirements": [],
|
||||
"dependencies": [],
|
||||
"dependencies": ["ffmpeg"],
|
||||
"codeowners": []
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"requirements": [
|
||||
"pywebpush==1.9.2"
|
||||
],
|
||||
"dependencies": [],
|
||||
"dependencies": ["frontend"],
|
||||
"codeowners": [
|
||||
"@robbiet480"
|
||||
]
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
"name": "Meraki",
|
||||
"documentation": "https://www.home-assistant.io/components/meraki",
|
||||
"requirements": [],
|
||||
"dependencies": [],
|
||||
"dependencies": ["http"],
|
||||
"codeowners": []
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
"name": "Microsoft face detect",
|
||||
"documentation": "https://www.home-assistant.io/components/microsoft_face_detect",
|
||||
"requirements": [],
|
||||
"dependencies": [],
|
||||
"dependencies": ["microsoft_face"],
|
||||
"codeowners": []
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
"name": "Microsoft face identify",
|
||||
"documentation": "https://www.home-assistant.io/components/microsoft_face_identify",
|
||||
"requirements": [],
|
||||
"dependencies": [],
|
||||
"dependencies": ["microsoft_face"],
|
||||
"codeowners": []
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
"name": "Push",
|
||||
"documentation": "https://www.home-assistant.io/components/push",
|
||||
"requirements": [],
|
||||
"dependencies": [],
|
||||
"dependencies": ["webhook"],
|
||||
"codeowners": [
|
||||
"@dgomes"
|
||||
]
|
||||
|
|
|
@ -244,7 +244,7 @@ def async_fire_mqtt_message(hass, topic, payload, qos=0, retain=False):
|
|||
if isinstance(payload, str):
|
||||
payload = payload.encode('utf-8')
|
||||
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)
|
||||
|
@ -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)
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_mock_mqtt_component(hass, config=None):
|
||||
async def async_mock_mqtt_component(hass, config=None):
|
||||
"""Mock the MQTT component."""
|
||||
if config is None:
|
||||
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().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
|
||||
})
|
||||
assert result
|
||||
await hass.async_block_till_done()
|
||||
|
||||
hass.data['mqtt'] = MagicMock(spec_set=hass.data['mqtt'],
|
||||
wraps=hass.data['mqtt'])
|
||||
|
@ -708,7 +708,7 @@ def assert_setup_component(count, domain=None):
|
|||
yield config
|
||||
|
||||
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())))
|
||||
domain = list(config.keys())[0]
|
||||
|
||||
|
|
|
@ -38,10 +38,12 @@ class TestDemoPlatform(unittest.TestCase):
|
|||
with patch('homeassistant.util.dt.utcnow', return_value=utcnow):
|
||||
with assert_setup_component(1, geo_location.DOMAIN):
|
||||
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.
|
||||
all_states = self.hass.states.all()
|
||||
print(all_states)
|
||||
assert len(all_states) == NUMBER_OF_DEMO_DEVICES
|
||||
|
||||
# Check a single device's attributes.
|
||||
|
|
|
@ -45,6 +45,7 @@ class TestNotifyDemo(unittest.TestCase):
|
|||
with assert_setup_component(1) as config:
|
||||
assert setup_component(self.hass, notify.DOMAIN, CONFIG)
|
||||
assert config[notify.DOMAIN]
|
||||
self.hass.block_till_done()
|
||||
|
||||
def test_setup(self):
|
||||
"""Test setup."""
|
||||
|
|
|
@ -29,6 +29,7 @@ class TestFFmpegNoiseSetup:
|
|||
"""Set up ffmpeg component."""
|
||||
with assert_setup_component(1, 'binary_sensor'):
|
||||
setup_component(self.hass, 'binary_sensor', self.config)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||
assert self.hass.states.get('binary_sensor.ffmpeg_noise') is not None
|
||||
|
@ -39,6 +40,7 @@ class TestFFmpegNoiseSetup:
|
|||
"""Set up ffmpeg component."""
|
||||
with assert_setup_component(1, 'binary_sensor'):
|
||||
setup_component(self.hass, 'binary_sensor', self.config)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||
assert self.hass.states.get('binary_sensor.ffmpeg_noise') is not None
|
||||
|
@ -54,6 +56,7 @@ class TestFFmpegNoiseSetup:
|
|||
"""Set up ffmpeg component."""
|
||||
with assert_setup_component(1, 'binary_sensor'):
|
||||
setup_component(self.hass, 'binary_sensor', self.config)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||
assert self.hass.states.get('binary_sensor.ffmpeg_noise') is not None
|
||||
|
@ -92,6 +95,7 @@ class TestFFmpegMotionSetup:
|
|||
"""Set up ffmpeg component."""
|
||||
with assert_setup_component(1, 'binary_sensor'):
|
||||
setup_component(self.hass, 'binary_sensor', self.config)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||
assert self.hass.states.get('binary_sensor.ffmpeg_motion') is not None
|
||||
|
@ -102,6 +106,7 @@ class TestFFmpegMotionSetup:
|
|||
"""Set up ffmpeg component."""
|
||||
with assert_setup_component(1, 'binary_sensor'):
|
||||
setup_component(self.hass, 'binary_sensor', self.config)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||
assert self.hass.states.get('binary_sensor.ffmpeg_motion') is not None
|
||||
|
@ -117,6 +122,7 @@ class TestFFmpegMotionSetup:
|
|||
"""Set up ffmpeg component."""
|
||||
with assert_setup_component(1, 'binary_sensor'):
|
||||
setup_component(self.hass, 'binary_sensor', self.config)
|
||||
self.hass.block_till_done()
|
||||
|
||||
assert self.hass.data['ffmpeg'].binary == 'ffmpeg'
|
||||
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
|
||||
def geofency_client(loop, hass, aiohttp_client):
|
||||
async def geofency_client(loop, hass, aiohttp_client):
|
||||
"""Geofency mock client (unauthenticated)."""
|
||||
assert loop.run_until_complete(async_setup_component(
|
||||
hass, 'persistent_notification', {}))
|
||||
assert await async_setup_component(
|
||||
hass, 'persistent_notification', {})
|
||||
|
||||
assert loop.run_until_complete(async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass, DOMAIN, {
|
||||
DOMAIN: {
|
||||
CONF_MOBILE_BEACONS: ['Car 1']
|
||||
}}))
|
||||
|
||||
loop.run_until_complete(hass.async_block_till_done())
|
||||
}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
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)
|
||||
def setup_zones(loop, hass):
|
||||
async def setup_zones(loop, hass):
|
||||
"""Set up Zone config in HA."""
|
||||
assert loop.run_until_complete(async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass, zone.DOMAIN, {
|
||||
'zone': {
|
||||
'name': 'Home',
|
||||
'latitude': HOME_LATITUDE,
|
||||
'longitude': HOME_LONGITUDE,
|
||||
'radius': 100,
|
||||
}}))
|
||||
}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -156,6 +156,7 @@ async def webhook_id(hass, geofency_client):
|
|||
result['flow_id'], {})
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
await hass.async_block_till_done()
|
||||
return result['result'].data['webhook_id']
|
||||
|
||||
|
||||
|
|
|
@ -26,31 +26,34 @@ def mock_dev_track(mock_device_tracker_conf):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def gpslogger_client(loop, hass, aiohttp_client):
|
||||
async def gpslogger_client(loop, hass, aiohttp_client):
|
||||
"""Mock client for GPSLogger (unauthenticated)."""
|
||||
assert loop.run_until_complete(async_setup_component(
|
||||
hass, 'persistent_notification', {}))
|
||||
assert await async_setup_component(
|
||||
hass, 'persistent_notification', {})
|
||||
|
||||
assert loop.run_until_complete(async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass, DOMAIN, {
|
||||
DOMAIN: {}
|
||||
}))
|
||||
})
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
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)
|
||||
def setup_zones(loop, hass):
|
||||
async def setup_zones(loop, hass):
|
||||
"""Set up Zone config in HA."""
|
||||
assert loop.run_until_complete(async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass, zone.DOMAIN, {
|
||||
'zone': {
|
||||
'name': 'Home',
|
||||
'latitude': HOME_LATITUDE,
|
||||
'longitude': HOME_LONGITUDE,
|
||||
'radius': 100,
|
||||
}}))
|
||||
}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -66,6 +69,7 @@ async def webhook_id(hass, gpslogger_client):
|
|||
result['flow_id'], {})
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
await hass.async_block_till_done()
|
||||
return result['result'].data['webhook_id']
|
||||
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ async def mock_client(hass, hass_client, registrations=None):
|
|||
'platform': 'html5'
|
||||
}
|
||||
})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
return await hass_client()
|
||||
|
||||
|
|
|
@ -374,10 +374,10 @@ class TestLight(unittest.TestCase):
|
|||
return True
|
||||
return real_isfile(path)
|
||||
|
||||
def _mock_open(path):
|
||||
def _mock_open(path, *args, **kwargs):
|
||||
if path == user_light_file:
|
||||
return StringIO(profile_data)
|
||||
return real_open(path)
|
||||
return real_open(path, *args, **kwargs)
|
||||
|
||||
profile_data = "id,x,y,brightness\n" +\
|
||||
"group.all_lights.default,.4,.6,99\n"
|
||||
|
@ -412,10 +412,10 @@ class TestLight(unittest.TestCase):
|
|||
return True
|
||||
return real_isfile(path)
|
||||
|
||||
def _mock_open(path):
|
||||
def _mock_open(path, *args, **kwargs):
|
||||
if path == user_light_file:
|
||||
return StringIO(profile_data)
|
||||
return real_open(path)
|
||||
return real_open(path, *args, **kwargs)
|
||||
|
||||
profile_data = "id,x,y,brightness\n" +\
|
||||
"group.all_lights.default,.3,.5,200\n" +\
|
||||
|
|
|
@ -22,15 +22,16 @@ def mock_dev_track(mock_device_tracker_conf):
|
|||
|
||||
|
||||
@pytest.fixture
|
||||
def locative_client(loop, hass, hass_client):
|
||||
async def locative_client(loop, hass, hass_client):
|
||||
"""Locative mock client."""
|
||||
assert loop.run_until_complete(async_setup_component(
|
||||
assert await async_setup_component(
|
||||
hass, DOMAIN, {
|
||||
DOMAIN: {}
|
||||
}))
|
||||
})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
with patch('homeassistant.components.device_tracker.update_config'):
|
||||
yield loop.run_until_complete(hass_client())
|
||||
return await hass_client()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -45,6 +46,7 @@ async def webhook_id(hass, locative_client):
|
|||
result = await hass.config_entries.flow.async_configure(
|
||||
result['flow_id'], {})
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
await hass.async_block_till_done()
|
||||
|
||||
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."""
|
||||
assert await async_setup_component(
|
||||
hass, 'mqtt', {'mqtt': {'broker': 'bla'}})
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_finish_setup.mock_calls) == 1
|
||||
|
||||
mock_try_connection.return_value = True
|
||||
|
|
|
@ -28,8 +28,7 @@ def mock_MQTT():
|
|||
yield mock_MQTT
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_mock_mqtt_client(hass, config=None):
|
||||
async def async_mock_mqtt_client(hass, config=None):
|
||||
"""Mock the MQTT paho client."""
|
||||
if config is None:
|
||||
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().unsubscribe.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
|
||||
})
|
||||
assert result
|
||||
await hass.async_block_till_done()
|
||||
return mock_client()
|
||||
|
||||
|
||||
|
|
|
@ -36,9 +36,8 @@ class TestMQTT:
|
|||
assert setup_component(self.hass, mqtt.DOMAIN, {
|
||||
mqtt.DOMAIN: {CONF_PASSWORD: password},
|
||||
})
|
||||
self.hass.block_till_done()
|
||||
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]['password'] == password
|
||||
|
||||
|
@ -61,9 +60,8 @@ class TestMQTT:
|
|||
'http': {'api_password': 'http_secret'},
|
||||
mqtt.DOMAIN: {CONF_PASSWORD: password},
|
||||
})
|
||||
self.hass.block_till_done()
|
||||
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]['password'] == password
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ async def test_config_yaml_host_not_imported(hass):
|
|||
'host': 'mock-host'
|
||||
}
|
||||
})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(mock_init.mock_calls) == 0
|
||||
|
||||
|
@ -34,6 +35,7 @@ async def test_config_yaml_host_imported(hass):
|
|||
'host': 'mock-host'
|
||||
}
|
||||
})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
progress = hass.config_entries.flow.async_progress()
|
||||
assert len(progress) == 1
|
||||
|
@ -54,6 +56,7 @@ async def test_config_json_host_not_imported(hass):
|
|||
assert await async_setup_component(hass, 'tradfri', {
|
||||
'tradfri': {}
|
||||
})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
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', {
|
||||
'tradfri': {}
|
||||
})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
progress = hass.config_entries.flow.async_progress()
|
||||
assert len(progress) == 1
|
||||
|
|
Loading…
Reference in New Issue