Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -8,7 +8,11 @@ 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)
|
||||
get_test_home_assistant,
|
||||
assert_setup_component,
|
||||
load_fixture,
|
||||
mock_coro,
|
||||
)
|
||||
from tests.components.image_processing import common
|
||||
|
||||
|
||||
@@ -23,56 +27,46 @@ class TestMicrosoftFaceDetectSetup:
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@patch('homeassistant.components.microsoft_face.'
|
||||
'MicrosoftFace.update_store', return_value=mock_coro())
|
||||
@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_detect',
|
||||
'source': {
|
||||
'entity_id': 'camera.demo_camera'
|
||||
},
|
||||
'attributes': ['age', 'gender'],
|
||||
"platform": "microsoft_face_detect",
|
||||
"source": {"entity_id": "camera.demo_camera"},
|
||||
"attributes": ["age", "gender"],
|
||||
},
|
||||
'camera': {
|
||||
'platform': 'demo'
|
||||
},
|
||||
mf.DOMAIN: {
|
||||
'api_key': '12345678abcdef6',
|
||||
}
|
||||
"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')
|
||||
assert self.hass.states.get("image_processing.microsoftface_demo_camera")
|
||||
|
||||
@patch('homeassistant.components.microsoft_face.'
|
||||
'MicrosoftFace.update_store', return_value=mock_coro())
|
||||
@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_detect',
|
||||
'source': {
|
||||
'entity_id': 'camera.demo_camera',
|
||||
'name': 'test local'
|
||||
},
|
||||
"platform": "microsoft_face_detect",
|
||||
"source": {"entity_id": "camera.demo_camera", "name": "test local"},
|
||||
},
|
||||
'camera': {
|
||||
'platform': 'demo'
|
||||
},
|
||||
mf.DOMAIN: {
|
||||
'api_key': '12345678abcdef6',
|
||||
}
|
||||
"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')
|
||||
assert self.hass.states.get("image_processing.test_local")
|
||||
|
||||
|
||||
class TestMicrosoftFaceDetect:
|
||||
@@ -84,19 +78,12 @@ class TestMicrosoftFaceDetect:
|
||||
|
||||
self.config = {
|
||||
ip.DOMAIN: {
|
||||
'platform': 'microsoft_face_detect',
|
||||
'source': {
|
||||
'entity_id': 'camera.demo_camera',
|
||||
'name': 'test local'
|
||||
},
|
||||
'attributes': ['age', 'gender'],
|
||||
"platform": "microsoft_face_detect",
|
||||
"source": {"entity_id": "camera.demo_camera", "name": "test local"},
|
||||
"attributes": ["age", "gender"],
|
||||
},
|
||||
'camera': {
|
||||
'platform': 'demo'
|
||||
},
|
||||
mf.DOMAIN: {
|
||||
'api_key': '12345678abcdef6',
|
||||
}
|
||||
"camera": {"platform": "demo"},
|
||||
mf.DOMAIN: {"api_key": "12345678abcdef6"},
|
||||
}
|
||||
|
||||
self.endpoint_url = "https://westus.{0}".format(mf.FACE_API_URL)
|
||||
@@ -105,30 +92,32 @@ class TestMicrosoftFaceDetect:
|
||||
"""Stop everything that was started."""
|
||||
self.hass.stop()
|
||||
|
||||
@patch('homeassistant.components.microsoft_face_detect.image_processing.'
|
||||
'MicrosoftFaceDetectEntity.should_poll',
|
||||
new_callable=PropertyMock(return_value=False))
|
||||
@patch(
|
||||
"homeassistant.components.microsoft_face_detect.image_processing."
|
||||
"MicrosoftFaceDetectEntity.should_poll",
|
||||
new_callable=PropertyMock(return_value=False),
|
||||
)
|
||||
def test_ms_detect_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')
|
||||
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')
|
||||
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')
|
||||
text=load_fixture("microsoft_face_persons.json"),
|
||||
)
|
||||
|
||||
setup_component(self.hass, ip.DOMAIN, self.config)
|
||||
|
||||
state = self.hass.states.get('camera.demo_camera')
|
||||
state = self.hass.states.get("camera.demo_camera")
|
||||
url = "{0}{1}".format(
|
||||
self.hass.config.api.base_url,
|
||||
state.attributes.get(ATTR_ENTITY_PICTURE))
|
||||
self.hass.config.api.base_url, state.attributes.get(ATTR_ENTITY_PICTURE)
|
||||
)
|
||||
|
||||
face_events = []
|
||||
|
||||
@@ -137,29 +126,28 @@ class TestMicrosoftFaceDetect:
|
||||
"""Mock event."""
|
||||
face_events.append(event)
|
||||
|
||||
self.hass.bus.listen('image_processing.detect_face', mock_face_event)
|
||||
self.hass.bus.listen("image_processing.detect_face", mock_face_event)
|
||||
|
||||
aioclient_mock.get(url, content=b'image')
|
||||
aioclient_mock.get(url, content=b"image")
|
||||
|
||||
aioclient_mock.post(
|
||||
self.endpoint_url.format("detect"),
|
||||
text=load_fixture('microsoft_face_detect.json'),
|
||||
params={'returnFaceAttributes': "age,gender"}
|
||||
text=load_fixture("microsoft_face_detect.json"),
|
||||
params={"returnFaceAttributes": "age,gender"},
|
||||
)
|
||||
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
common.scan(self.hass, entity_id="image_processing.test_local")
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
state = self.hass.states.get("image_processing.test_local")
|
||||
|
||||
assert len(face_events) == 1
|
||||
assert state.attributes.get('total_faces') == 1
|
||||
assert state.state == '1'
|
||||
assert state.attributes.get("total_faces") == 1
|
||||
assert state.state == "1"
|
||||
|
||||
assert face_events[0].data['age'] == 71.0
|
||||
assert face_events[0].data['gender'] == 'male'
|
||||
assert face_events[0].data['entity_id'] == \
|
||||
'image_processing.test_local'
|
||||
assert face_events[0].data["age"] == 71.0
|
||||
assert face_events[0].data["gender"] == "male"
|
||||
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
|
||||
@@ -167,16 +155,16 @@ class TestMicrosoftFaceDetect:
|
||||
aioclient_mock.post(
|
||||
self.endpoint_url.format("detect"),
|
||||
text="[]",
|
||||
params={'returnFaceAttributes': "age,gender"}
|
||||
params={"returnFaceAttributes": "age,gender"},
|
||||
)
|
||||
|
||||
common.scan(self.hass, entity_id='image_processing.test_local')
|
||||
common.scan(self.hass, entity_id="image_processing.test_local")
|
||||
self.hass.block_till_done()
|
||||
|
||||
state = self.hass.states.get('image_processing.test_local')
|
||||
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 == '0'
|
||||
assert state.attributes.get("total_faces") == 0
|
||||
assert state.state == "0"
|
||||
Reference in new issue
Block a user