Consolidate all platforms that have tests (#22109)
* Moved climate components with tests into platform dirs. * Updated tests from climate component. * Moved binary_sensor components with tests into platform dirs. * Updated tests from binary_sensor component. * Moved calendar components with tests into platform dirs. * Updated tests from calendar component. * Moved camera components with tests into platform dirs. * Updated tests from camera component. * Moved cover components with tests into platform dirs. * Updated tests from cover component. * Moved device_tracker components with tests into platform dirs. * Updated tests from device_tracker component. * Moved fan components with tests into platform dirs. * Updated tests from fan component. * Moved geo_location components with tests into platform dirs. * Updated tests from geo_location component. * Moved image_processing components with tests into platform dirs. * Updated tests from image_processing component. * Moved light components with tests into platform dirs. * Updated tests from light component. * Moved lock components with tests into platform dirs. * Moved media_player components with tests into platform dirs. * Updated tests from media_player component. * Moved scene components with tests into platform dirs. * Moved sensor components with tests into platform dirs. * Updated tests from sensor component. * Moved switch components with tests into platform dirs. * Updated tests from sensor component. * Moved vacuum components with tests into platform dirs. * Updated tests from vacuum component. * Moved weather components with tests into platform dirs. * Fixed __init__.py files * Fixes for stuff moved as part of this branch. * Fix stuff needed to merge with balloob's branch. * Formatting issues. * Missing __init__.py files. * Fix-ups * Fixup * Regenerated requirements. * Linting errors fixed. * Fixed more broken tests. * Missing init files. * Fix broken tests. * More broken tests * There seems to be a thread race condition. I suspect the logger stuff is running in another thread, which means waiting until the aio loop is done is missing the log messages. Used sleep instead because that allows the logger thread to run. I think the api_streams sensor might not be thread safe. * Disabled tests, will remove sensor in #22147 * Updated coverage and codeowners.
This commit is contained in:
1 parent
46ece3603f
commit
f195ecca4b
486 files changed
+662
-455
No files matched your search
@@ -0,0 +1 @@
|
||||
"""Tests for the microsoft_face_identify component."""
|
||||
@@ -0,0 +1,185 @@
|
||||
"""The tests for the microsoft face identify platform."""
|
||||
from unittest.mock import patch, PropertyMock
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.const import ATTR_ENTITY_PICTURE, STATE_UNKNOWN
|
||||
from homeassistant.setup import setup_component
|
||||
import homeassistant.components.image_processing as ip
|
||||
import homeassistant.components.microsoft_face as mf
|
||||
|
||||
from tests.common import (
|
||||
get_test_home_assistant, assert_setup_component, load_fixture, mock_coro)
|
||||
from tests.components.image_processing import common
|
||||
|
||||
|
||||
class TestMicrosoftFaceIdentifySetup:
|
||||
"""Test class for image processing."""
|
||||
|
||||
def setup_method(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
def teardown_method(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@patch('homeassistant.components.microsoft_face.'
|
||||
'MicrosoftFace.update_store', return_value=mock_coro())
|
||||
def test_setup_platform(self, store_mock):
|
||||
"""Set up platform with one entity."""
|
||||
config = {
|
||||
ip.DOMAIN: {
|
||||
'platform': 'microsoft_face_identify',
|
||||
'source': {
|
||||
'entity_id': 'camera.demo_camera'
|
||||
},
|
||||
'group': 'Test Group1',
|
||||
},
|
||||
'camera': {
|
||||
'platform': 'demo'
|
||||
},
|
||||
mf.DOMAIN: {
|
||||
'api_key': '12345678abcdef6',
|
||||
}
|
||||
}
|
||||
|
||||
with assert_setup_component(1, ip.DOMAIN):
|
||||
setup_component(self.hass, ip.DOMAIN, config)
|
||||
|
||||
assert self.hass.states.get(
|
||||
'image_processing.microsoftface_demo_camera')
|
||||
|
||||
@patch('homeassistant.components.microsoft_face.'
|
||||
'MicrosoftFace.update_store', return_value=mock_coro())
|
||||
def test_setup_platform_name(self, store_mock):
|
||||
"""Set up platform with one entity and set name."""
|
||||
config = {
|
||||
ip.DOMAIN: {
|
||||
'platform': 'microsoft_face_identify',
|
||||
'source': {
|
||||
'entity_id': 'camera.demo_camera',
|
||||
'name': 'test local'
|
||||
},
|
||||
'group': 'Test Group1',
|
||||
},
|
||||
'camera': {
|
||||
'platform': 'demo'
|
||||
},
|
||||
mf.DOMAIN: {
|
||||
'api_key': '12345678abcdef6',
|
||||
}
|
||||
}
|
||||
|
||||
with assert_setup_component(1, ip.DOMAIN):
|
||||
setup_component(self.hass, ip.DOMAIN, config)
|
||||
|
||||
assert self.hass.states.get('image_processing.test_local')
|
||||
|
||||
|
||||
class TestMicrosoftFaceIdentify:
|
||||
"""Test class for image processing."""
|
||||
|
||||
def setup_method(self):
|
||||
"""Set up things to be run when tests are started."""
|
||||
self.hass = get_test_home_assistant()
|
||||
|
||||
self.config = {
|
||||
ip.DOMAIN: {
|
||||
'platform': 'microsoft_face_identify',
|
||||
'source': {
|
||||
'entity_id': 'camera.demo_camera',
|
||||
'name': 'test local'
|
||||
},
|
||||
'group': 'Test Group1',
|
||||
},
|
||||
'camera': {
|
||||
'platform': 'demo'
|
||||
},
|
||||
mf.DOMAIN: {
|
||||
'api_key': '12345678abcdef6',
|
||||
}
|
||||
}
|
||||
|
||||
self.endpoint_url = "https://westus.{0}".format(mf.FACE_API_URL)
|
||||
|
||||
def teardown_method(self):
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@patch('homeassistant.components.microsoft_face_identify.image_processing.'
|
||||
'MicrosoftFaceIdentifyEntity.should_poll',
|
||||
new_callable=PropertyMock(return_value=False))
|
||||
def test_ms_identify_process_image(self, poll_mock, aioclient_mock):
|
||||
"""Set up and scan a picture and test plates from event."""
|
||||
aioclient_mock.get(
|
||||
self.endpoint_url.format("persongroups"),
|
||||
text=load_fixture('microsoft_face_persongroups.json')
|
||||
)
|
||||
aioclient_mock.get(
|
||||
self.endpoint_url.format("persongroups/test_group1/persons"),
|
||||
text=load_fixture('microsoft_face_persons.json')
|
||||
)
|
||||
aioclient_mock.get(
|
||||
self.endpoint_url.format("persongroups/test_group2/persons"),
|
||||
text=load_fixture('microsoft_face_persons.json')
|
||||
)
|
||||
|
||||
setup_component(self.hass, ip.DOMAIN, self.config)
|
||||
|
||||
state = self.hass.states.get('camera.demo_camera')
|
||||
url = "{0}{1}".format(
|
||||
self.hass.config.api.base_url,
|
||||
state.attributes.get(ATTR_ENTITY_PICTURE))
|
||||
|
||||
face_events = []
|
||||
|
||||
@callback
|
||||
def mock_face_event(event):
|
||||
"""Mock event."""
|
||||
face_events.append(event)
|
||||
|
||||
self.hass.bus.listen('image_processing.detect_face', mock_face_event)
|
||||
|
||||
aioclient_mock.get(url, content=b'image')
|
||||
|
||||
aioclient_mock.post(
|
||||
self.endpoint_url.format("detect"),
|
||||
text=load_fixture('microsoft_face_detect.json')
|
||||
)
|
||||
aioclient_mock.post(
|
||||
self.endpoint_url.format("identify"),
|
||||
text=load_fixture('microsoft_face_identify.json')
|
||||
)
|
||||
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
|
||||
assert len(face_events) == 1
|
||||
assert state.attributes.get('total_faces') == 2
|
||||
assert state.state == 'David'
|
||||
|
||||
assert face_events[0].data['name'] == 'David'
|
||||
assert face_events[0].data['confidence'] == float(92)
|
||||
assert face_events[0].data['entity_id'] == \
|
||||
'image_processing.test_local'
|
||||
|
||||
# Test that later, if a request is made that results in no face
|
||||
# being detected, that this is reflected in the state object
|
||||
aioclient_mock.clear_requests()
|
||||
aioclient_mock.post(
|
||||
self.endpoint_url.format("detect"),
|
||||
text="[]"
|
||||
)
|
||||
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
|
||||
# No more face events were fired
|
||||
assert len(face_events) == 1
|
||||
# Total faces and actual qualified number of faces reset to zero
|
||||
assert state.attributes.get('total_faces') == 0
|
||||
assert state.state == STATE_UNKNOWN
|
||||
Reference in new issue
Block a user