'Setup and scan a picture and test plates from event.'

@patch('homeassistant.components.image_processing.microsoft_face_identify.MicrosoftFaceIdentifyEntity.should_poll', new_callable=PropertyMock(return_value=False))
def test_ms_identify_process_image(self, poll_mock, aioclient_mock):

    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='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'))
    ip.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')
