Support adding different server locations for Microsoft face component (#7532)

* Support adding different server locations

* Rename variables and move CONF_ const into component as requested in review

* Fix unittests

* Forgot to add tests for microsoft_face_identify
This commit is contained in:
Tsvi Mostovicz 2017-05-12 11:53:25 +03:00 committed by Pascal Vizeli
parent 8da10f670b
commit 452c3a1b25
4 changed files with 49 additions and 38 deletions

View file

@ -98,6 +98,8 @@ class TestMicrosoftFaceDetect(object):
}
}
self.endpoint_url = "https://westus.{0}".format(mf.FACE_API_URL)
def teardown_method(self):
"""Stop everything that was started."""
self.hass.stop()
@ -108,15 +110,15 @@ class TestMicrosoftFaceDetect(object):
def test_ms_detect_process_image(self, poll_mock, aioclient_mock):
"""Setup and scan a picture and test plates from event."""
aioclient_mock.get(
mf.FACE_API_URL.format("persongroups"),
self.endpoint_url.format("persongroups"),
text=load_fixture('microsoft_face_persongroups.json')
)
aioclient_mock.get(
mf.FACE_API_URL.format("persongroups/test_group1/persons"),
self.endpoint_url.format("persongroups/test_group1/persons"),
text=load_fixture('microsoft_face_persons.json')
)
aioclient_mock.get(
mf.FACE_API_URL.format("persongroups/test_group2/persons"),
self.endpoint_url.format("persongroups/test_group2/persons"),
text=load_fixture('microsoft_face_persons.json')
)
@ -139,7 +141,7 @@ class TestMicrosoftFaceDetect(object):
aioclient_mock.get(url, content=b'image')
aioclient_mock.post(
mf.FACE_API_URL.format("detect"),
self.endpoint_url.format("detect"),
text=load_fixture('microsoft_face_detect.json'),
params={'returnFaceAttributes': "age,gender"}
)

View file

@ -99,6 +99,8 @@ class TestMicrosoftFaceIdentify(object):
}
}
self.endpoint_url = "https://westus.{0}".format(mf.FACE_API_URL)
def teardown_method(self):
"""Stop everything that was started."""
self.hass.stop()
@ -109,15 +111,15 @@ class TestMicrosoftFaceIdentify(object):
def test_ms_identify_process_image(self, poll_mock, aioclient_mock):
"""Setup and scan a picture and test plates from event."""
aioclient_mock.get(
mf.FACE_API_URL.format("persongroups"),
self.endpoint_url.format("persongroups"),
text=load_fixture('microsoft_face_persongroups.json')
)
aioclient_mock.get(
mf.FACE_API_URL.format("persongroups/test_group1/persons"),
self.endpoint_url.format("persongroups/test_group1/persons"),
text=load_fixture('microsoft_face_persons.json')
)
aioclient_mock.get(
mf.FACE_API_URL.format("persongroups/test_group2/persons"),
self.endpoint_url.format("persongroups/test_group2/persons"),
text=load_fixture('microsoft_face_persons.json')
)
@ -140,11 +142,11 @@ class TestMicrosoftFaceIdentify(object):
aioclient_mock.get(url, content=b'image')
aioclient_mock.post(
mf.FACE_API_URL.format("detect"),
self.endpoint_url.format("detect"),
text=load_fixture('microsoft_face_detect.json')
)
aioclient_mock.post(
mf.FACE_API_URL.format("identify"),
self.endpoint_url.format("identify"),
text=load_fixture('microsoft_face_identify.json')
)