mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Migrate mailbox tests from coroutine to async/await (#30361)
This commit is contained in:
parent
99bc911f7f
commit
3a4db2fae7
@ -1,5 +1,4 @@
|
|||||||
"""The tests for the mailbox component."""
|
"""The tests for the mailbox component."""
|
||||||
import asyncio
|
|
||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -16,44 +15,40 @@ def mock_http_client(hass, hass_client):
|
|||||||
return hass.loop.run_until_complete(hass_client())
|
return hass.loop.run_until_complete(hass_client())
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_platforms_from_mailbox(mock_http_client):
|
||||||
def test_get_platforms_from_mailbox(mock_http_client):
|
|
||||||
"""Get platforms from mailbox."""
|
"""Get platforms from mailbox."""
|
||||||
url = "/api/mailbox/platforms"
|
url = "/api/mailbox/platforms"
|
||||||
|
|
||||||
req = yield from mock_http_client.get(url)
|
req = await mock_http_client.get(url)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
result = yield from req.json()
|
result = await req.json()
|
||||||
assert len(result) == 1 and "DemoMailbox" == result[0].get("name", None)
|
assert len(result) == 1 and "DemoMailbox" == result[0].get("name", None)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_messages_from_mailbox(mock_http_client):
|
||||||
def test_get_messages_from_mailbox(mock_http_client):
|
|
||||||
"""Get messages from mailbox."""
|
"""Get messages from mailbox."""
|
||||||
url = "/api/mailbox/messages/DemoMailbox"
|
url = "/api/mailbox/messages/DemoMailbox"
|
||||||
|
|
||||||
req = yield from mock_http_client.get(url)
|
req = await mock_http_client.get(url)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
result = yield from req.json()
|
result = await req.json()
|
||||||
assert len(result) == 10
|
assert len(result) == 10
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_media_from_mailbox(mock_http_client):
|
||||||
def test_get_media_from_mailbox(mock_http_client):
|
|
||||||
"""Get audio from mailbox."""
|
"""Get audio from mailbox."""
|
||||||
mp3sha = "3f67c4ea33b37d1710f772a26dd3fb43bb159d50"
|
mp3sha = "3f67c4ea33b37d1710f772a26dd3fb43bb159d50"
|
||||||
msgtxt = "Message 1. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
msgtxt = "Message 1. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
||||||
msgsha = sha1(msgtxt.encode("utf-8")).hexdigest()
|
msgsha = sha1(msgtxt.encode("utf-8")).hexdigest()
|
||||||
|
|
||||||
url = "/api/mailbox/media/DemoMailbox/%s" % (msgsha)
|
url = "/api/mailbox/media/DemoMailbox/%s" % (msgsha)
|
||||||
req = yield from mock_http_client.get(url)
|
req = await mock_http_client.get(url)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
data = yield from req.read()
|
data = await req.read()
|
||||||
assert sha1(data).hexdigest() == mp3sha
|
assert sha1(data).hexdigest() == mp3sha
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_delete_from_mailbox(mock_http_client):
|
||||||
def test_delete_from_mailbox(mock_http_client):
|
|
||||||
"""Get audio from mailbox."""
|
"""Get audio from mailbox."""
|
||||||
msgtxt1 = "Message 1. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
msgtxt1 = "Message 1. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
||||||
msgtxt2 = "Message 3. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
msgtxt2 = "Message 3. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
|
||||||
@ -62,50 +57,46 @@ def test_delete_from_mailbox(mock_http_client):
|
|||||||
|
|
||||||
for msg in [msgsha1, msgsha2]:
|
for msg in [msgsha1, msgsha2]:
|
||||||
url = "/api/mailbox/delete/DemoMailbox/%s" % (msg)
|
url = "/api/mailbox/delete/DemoMailbox/%s" % (msg)
|
||||||
req = yield from mock_http_client.delete(url)
|
req = await mock_http_client.delete(url)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
|
|
||||||
url = "/api/mailbox/messages/DemoMailbox"
|
url = "/api/mailbox/messages/DemoMailbox"
|
||||||
req = yield from mock_http_client.get(url)
|
req = await mock_http_client.get(url)
|
||||||
assert req.status == 200
|
assert req.status == 200
|
||||||
result = yield from req.json()
|
result = await req.json()
|
||||||
assert len(result) == 8
|
assert len(result) == 8
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_messages_from_invalid_mailbox(mock_http_client):
|
||||||
def test_get_messages_from_invalid_mailbox(mock_http_client):
|
|
||||||
"""Get messages from mailbox."""
|
"""Get messages from mailbox."""
|
||||||
url = "/api/mailbox/messages/mailbox.invalid_mailbox"
|
url = "/api/mailbox/messages/mailbox.invalid_mailbox"
|
||||||
|
|
||||||
req = yield from mock_http_client.get(url)
|
req = await mock_http_client.get(url)
|
||||||
assert req.status == 404
|
assert req.status == 404
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_media_from_invalid_mailbox(mock_http_client):
|
||||||
def test_get_media_from_invalid_mailbox(mock_http_client):
|
|
||||||
"""Get messages from mailbox."""
|
"""Get messages from mailbox."""
|
||||||
msgsha = "0000000000000000000000000000000000000000"
|
msgsha = "0000000000000000000000000000000000000000"
|
||||||
url = "/api/mailbox/media/mailbox.invalid_mailbox/%s" % (msgsha)
|
url = "/api/mailbox/media/mailbox.invalid_mailbox/%s" % (msgsha)
|
||||||
|
|
||||||
req = yield from mock_http_client.get(url)
|
req = await mock_http_client.get(url)
|
||||||
assert req.status == 404
|
assert req.status == 404
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_get_media_from_invalid_msgid(mock_http_client):
|
||||||
def test_get_media_from_invalid_msgid(mock_http_client):
|
|
||||||
"""Get messages from mailbox."""
|
"""Get messages from mailbox."""
|
||||||
msgsha = "0000000000000000000000000000000000000000"
|
msgsha = "0000000000000000000000000000000000000000"
|
||||||
url = "/api/mailbox/media/DemoMailbox/%s" % (msgsha)
|
url = "/api/mailbox/media/DemoMailbox/%s" % (msgsha)
|
||||||
|
|
||||||
req = yield from mock_http_client.get(url)
|
req = await mock_http_client.get(url)
|
||||||
assert req.status == 500
|
assert req.status == 500
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_delete_from_invalid_mailbox(mock_http_client):
|
||||||
def test_delete_from_invalid_mailbox(mock_http_client):
|
|
||||||
"""Get audio from mailbox."""
|
"""Get audio from mailbox."""
|
||||||
msgsha = "0000000000000000000000000000000000000000"
|
msgsha = "0000000000000000000000000000000000000000"
|
||||||
url = "/api/mailbox/delete/mailbox.invalid_mailbox/%s" % (msgsha)
|
url = "/api/mailbox/delete/mailbox.invalid_mailbox/%s" % (msgsha)
|
||||||
|
|
||||||
req = yield from mock_http_client.delete(url)
|
req = await mock_http_client.delete(url)
|
||||||
assert req.status == 404
|
assert req.status == 404
|
||||||
|
Loading…
x
Reference in New Issue
Block a user