Migrate alexa tests from coroutine to async/await (#30332)
parent
0280862780
commit
2ac5537495
|
@ -1,6 +1,5 @@
|
||||||
"""The tests for the Alexa component."""
|
"""The tests for the Alexa component."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
import asyncio
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -67,21 +66,19 @@ def _flash_briefing_req(client, briefing_id):
|
||||||
return client.get("/api/alexa/flash_briefings/{}".format(briefing_id))
|
return client.get("/api/alexa/flash_briefings/{}".format(briefing_id))
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_flash_briefing_invalid_id(alexa_client):
|
||||||
def test_flash_briefing_invalid_id(alexa_client):
|
|
||||||
"""Test an invalid Flash Briefing ID."""
|
"""Test an invalid Flash Briefing ID."""
|
||||||
req = yield from _flash_briefing_req(alexa_client, 10000)
|
req = await _flash_briefing_req(alexa_client, 10000)
|
||||||
assert req.status == 404
|
assert req.status == 404
|
||||||
text = yield from req.text()
|
text = await req.text()
|
||||||
assert text == ""
|
assert text == ""
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_flash_briefing_date_from_str(alexa_client):
|
||||||
def test_flash_briefing_date_from_str(alexa_client):
|
|
||||||
"""Test the response has a valid date parsed from string."""
|
"""Test the response has a valid date parsed from string."""
|
||||||
req = yield from _flash_briefing_req(alexa_client, "weather")
|
req = await _flash_briefing_req(alexa_client, "weather")
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
data = yield from req.json()
|
data = await req.json()
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
datetime.datetime.strptime(
|
datetime.datetime.strptime(
|
||||||
data[0].get(const.ATTR_UPDATE_DATE), const.DATE_FORMAT
|
data[0].get(const.ATTR_UPDATE_DATE), const.DATE_FORMAT
|
||||||
|
@ -90,8 +87,7 @@ def test_flash_briefing_date_from_str(alexa_client):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_flash_briefing_valid(alexa_client):
|
||||||
def test_flash_briefing_valid(alexa_client):
|
|
||||||
"""Test the response is valid."""
|
"""Test the response is valid."""
|
||||||
data = [
|
data = [
|
||||||
{
|
{
|
||||||
|
@ -104,9 +100,9 @@ def test_flash_briefing_valid(alexa_client):
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
req = yield from _flash_briefing_req(alexa_client, "news_audio")
|
req = await _flash_briefing_req(alexa_client, "news_audio")
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
json = yield from req.json()
|
json = await req.json()
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
datetime.datetime.strptime(
|
datetime.datetime.strptime(
|
||||||
json[0].get(const.ATTR_UPDATE_DATE), const.DATE_FORMAT
|
json[0].get(const.ATTR_UPDATE_DATE), const.DATE_FORMAT
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""The tests for the Alexa component."""
|
"""The tests for the Alexa component."""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -115,8 +114,7 @@ def _intent_req(client, data=None):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_launch_request(alexa_client):
|
||||||
def test_intent_launch_request(alexa_client):
|
|
||||||
"""Test the launch of a request."""
|
"""Test the launch of a request."""
|
||||||
data = {
|
data = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
@ -133,15 +131,14 @@ def test_intent_launch_request(alexa_client):
|
||||||
"timestamp": "2015-05-13T12:34:56Z",
|
"timestamp": "2015-05-13T12:34:56Z",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
data = yield from req.json()
|
data = await req.json()
|
||||||
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
||||||
assert text == "LaunchRequest has been received."
|
assert text == "LaunchRequest has been received."
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_launch_request_not_configured(alexa_client):
|
||||||
def test_intent_launch_request_not_configured(alexa_client):
|
|
||||||
"""Test the launch of a request."""
|
"""Test the launch of a request."""
|
||||||
data = {
|
data = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
@ -160,15 +157,14 @@ def test_intent_launch_request_not_configured(alexa_client):
|
||||||
"timestamp": "2015-05-13T12:34:56Z",
|
"timestamp": "2015-05-13T12:34:56Z",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
data = yield from req.json()
|
data = await req.json()
|
||||||
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
||||||
assert text == "This intent is not yet configured within Home Assistant."
|
assert text == "This intent is not yet configured within Home Assistant."
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_request_with_slots(alexa_client):
|
||||||
def test_intent_request_with_slots(alexa_client):
|
|
||||||
"""Test a request with slots."""
|
"""Test a request with slots."""
|
||||||
data = {
|
data = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
@ -195,15 +191,14 @@ def test_intent_request_with_slots(alexa_client):
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
data = yield from req.json()
|
data = await req.json()
|
||||||
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
||||||
assert text == "You told us your sign is virgo."
|
assert text == "You told us your sign is virgo."
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_request_with_slots_and_synonym_resolution(alexa_client):
|
||||||
def test_intent_request_with_slots_and_synonym_resolution(alexa_client):
|
|
||||||
"""Test a request with slots and a name synonym."""
|
"""Test a request with slots and a name synonym."""
|
||||||
data = {
|
data = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
@ -249,15 +244,14 @@ def test_intent_request_with_slots_and_synonym_resolution(alexa_client):
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
data = yield from req.json()
|
data = await req.json()
|
||||||
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
||||||
assert text == "You told us your sign is Virgo."
|
assert text == "You told us your sign is Virgo."
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_request_with_slots_and_multi_synonym_resolution(alexa_client):
|
||||||
def test_intent_request_with_slots_and_multi_synonym_resolution(alexa_client):
|
|
||||||
"""Test a request with slots and multiple name synonyms."""
|
"""Test a request with slots and multiple name synonyms."""
|
||||||
data = {
|
data = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
@ -303,15 +297,14 @@ def test_intent_request_with_slots_and_multi_synonym_resolution(alexa_client):
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
data = yield from req.json()
|
data = await req.json()
|
||||||
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
||||||
assert text == "You told us your sign is V zodiac."
|
assert text == "You told us your sign is V zodiac."
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_request_with_slots_but_no_value(alexa_client):
|
||||||
def test_intent_request_with_slots_but_no_value(alexa_client):
|
|
||||||
"""Test a request with slots but no value."""
|
"""Test a request with slots but no value."""
|
||||||
data = {
|
data = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
@ -338,15 +331,14 @@ def test_intent_request_with_slots_but_no_value(alexa_client):
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
data = yield from req.json()
|
data = await req.json()
|
||||||
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
||||||
assert text == "You told us your sign is ."
|
assert text == "You told us your sign is ."
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_request_without_slots(hass, alexa_client):
|
||||||
def test_intent_request_without_slots(hass, alexa_client):
|
|
||||||
"""Test a request without slots."""
|
"""Test a request without slots."""
|
||||||
data = {
|
data = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
@ -370,9 +362,9 @@ def test_intent_request_without_slots(hass, alexa_client):
|
||||||
"intent": {"name": "WhereAreWeIntent"},
|
"intent": {"name": "WhereAreWeIntent"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
json = yield from req.json()
|
json = await req.json()
|
||||||
text = json.get("response", {}).get("outputSpeech", {}).get("text")
|
text = json.get("response", {}).get("outputSpeech", {}).get("text")
|
||||||
|
|
||||||
assert text == "Anne Therese is at unknown and Paulus is at unknown"
|
assert text == "Anne Therese is at unknown and Paulus is at unknown"
|
||||||
|
@ -380,15 +372,14 @@ def test_intent_request_without_slots(hass, alexa_client):
|
||||||
hass.states.async_set("device_tracker.paulus", "home")
|
hass.states.async_set("device_tracker.paulus", "home")
|
||||||
hass.states.async_set("device_tracker.anne_therese", "home")
|
hass.states.async_set("device_tracker.anne_therese", "home")
|
||||||
|
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
json = yield from req.json()
|
json = await req.json()
|
||||||
text = json.get("response", {}).get("outputSpeech", {}).get("text")
|
text = json.get("response", {}).get("outputSpeech", {}).get("text")
|
||||||
assert text == "You are both home, you silly"
|
assert text == "You are both home, you silly"
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_request_calling_service(alexa_client):
|
||||||
def test_intent_request_calling_service(alexa_client):
|
|
||||||
"""Test a request for calling a service."""
|
"""Test a request for calling a service."""
|
||||||
data = {
|
data = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
@ -410,7 +401,7 @@ def test_intent_request_calling_service(alexa_client):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
call_count = len(calls)
|
call_count = len(calls)
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
assert call_count + 1 == len(calls)
|
assert call_count + 1 == len(calls)
|
||||||
call = calls[-1]
|
call = calls[-1]
|
||||||
|
@ -419,15 +410,14 @@ def test_intent_request_calling_service(alexa_client):
|
||||||
assert call.data.get("entity_id") == ["switch.test"]
|
assert call.data.get("entity_id") == ["switch.test"]
|
||||||
assert call.data.get("hello") == "virgo"
|
assert call.data.get("hello") == "virgo"
|
||||||
|
|
||||||
data = yield from req.json()
|
data = await req.json()
|
||||||
assert data["response"]["card"]["title"] == "Card title for virgo"
|
assert data["response"]["card"]["title"] == "Card title for virgo"
|
||||||
assert data["response"]["card"]["content"] == "Card content: virgo"
|
assert data["response"]["card"]["content"] == "Card content: virgo"
|
||||||
assert data["response"]["outputSpeech"]["type"] == "PlainText"
|
assert data["response"]["outputSpeech"]["type"] == "PlainText"
|
||||||
assert data["response"]["outputSpeech"]["text"] == "Service called for virgo"
|
assert data["response"]["outputSpeech"]["text"] == "Service called for virgo"
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_session_ended_request(alexa_client):
|
||||||
def test_intent_session_ended_request(alexa_client):
|
|
||||||
"""Test the request for ending the session."""
|
"""Test the request for ending the session."""
|
||||||
data = {
|
data = {
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
|
@ -452,14 +442,13 @@ def test_intent_session_ended_request(alexa_client):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
text = yield from req.text()
|
text = await req.text()
|
||||||
assert text == ""
|
assert text == ""
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_intent_from_built_in_intent_library(alexa_client):
|
||||||
def test_intent_from_built_in_intent_library(alexa_client):
|
|
||||||
"""Test intents from the Built-in Intent Library."""
|
"""Test intents from the Built-in Intent Library."""
|
||||||
data = {
|
data = {
|
||||||
"request": {
|
"request": {
|
||||||
|
@ -490,8 +479,8 @@ def test_intent_from_built_in_intent_library(alexa_client):
|
||||||
"application": {"applicationId": APPLICATION_ID},
|
"application": {"applicationId": APPLICATION_ID},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
req = yield from _intent_req(alexa_client, data)
|
req = await _intent_req(alexa_client, data)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
data = yield from req.json()
|
data = await req.json()
|
||||||
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
text = data.get("response", {}).get("outputSpeech", {}).get("text")
|
||||||
assert text == "Playing the shins."
|
assert text == "Playing the shins."
|
||||||
|
|
Loading…
Reference in New Issue