コード例 #1
0
    def test_service_person(self, aioclient_mock):
        """Setup component, test person services."""
        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')
        )

        with assert_setup_component(3, mf.DOMAIN):
            setup_component(self.hass, mf.DOMAIN, self.config)

        assert len(aioclient_mock.mock_calls) == 3

        aioclient_mock.post(
            self.endpoint_url.format("persongroups/test_group1/persons"),
            text=load_fixture('microsoft_face_create_person.json')
        )
        aioclient_mock.delete(
            self.endpoint_url.format(
                "persongroups/test_group1/persons/"
                "25985303-c537-4467-b41d-bdb45cd95ca1"),
            status=200, text="{}"
        )

        mf.create_person(self.hass, 'test group1', 'Hans')
        self.hass.block_till_done()

        entity_group1 = self.hass.states.get('microsoft_face.test_group1')

        assert len(aioclient_mock.mock_calls) == 4
        assert entity_group1 is not None
        assert entity_group1.attributes['Hans'] == \
            '25985303-c537-4467-b41d-bdb45cd95ca1'

        mf.delete_person(self.hass, 'test group1', 'Hans')
        self.hass.block_till_done()

        entity_group1 = self.hass.states.get('microsoft_face.test_group1')

        assert len(aioclient_mock.mock_calls) == 5
        assert entity_group1 is not None
        assert 'Hans' not in entity_group1.attributes
コード例 #2
0
    def test_service_person(self, aioclient_mock):
        """Setup component, test person services."""
        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')
        )

        with assert_setup_component(3, mf.DOMAIN):
            setup_component(self.hass, mf.DOMAIN, self.config)

        assert len(aioclient_mock.mock_calls) == 3

        aioclient_mock.post(
            self.endpoint_url.format("persongroups/test_group1/persons"),
            text=load_fixture('microsoft_face_create_person.json')
        )
        aioclient_mock.delete(
            self.endpoint_url.format(
                "persongroups/test_group1/persons/"
                "25985303-c537-4467-b41d-bdb45cd95ca1"),
            status=200, text="{}"
        )

        mf.create_person(self.hass, 'test group1', 'Hans')
        self.hass.block_till_done()

        entity_group1 = self.hass.states.get('microsoft_face.test_group1')

        assert len(aioclient_mock.mock_calls) == 4
        assert entity_group1 is not None
        assert entity_group1.attributes['Hans'] == \
            '25985303-c537-4467-b41d-bdb45cd95ca1'

        mf.delete_person(self.hass, 'test group1', 'Hans')
        self.hass.block_till_done()

        entity_group1 = self.hass.states.get('microsoft_face.test_group1')

        assert len(aioclient_mock.mock_calls) == 5
        assert entity_group1 is not None
        assert 'Hans' not in entity_group1.attributes