mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add Initial Mailbox panel and sensor (#8233)
* Initial implementation of Asterisk Mailbox * Rework asterisk_mbox handler to avoid using the hass.data hash. Fix requirements. * Handle potential asterisk server disconnect. bump asterisk_mbox requirement to 0.4.0 * Use async method for mp3 fetch from server * Add http as dependency * Minor log fix. try to force Travis to rebuild * Updates based on review * Fix error handling as per review * Fix error handling as per review * Refactor voicemail into mailbox component * Hide mailbox component from front page * Add demo for mailbox * Add tests for mailbox * Remove asterisk_mbox sensor and replace with a generic mailbox sensor * Fix linting errors * Remove mailbox sensor. Remove demo.mp3. Split entity from platform object. * Update mailbox test * Update mailbox test * Use events to indicate state change rather than entity last-updated * Make mailbox platform calls async. Fix other review concerns * Rewrite mailbox tests to live at root level and be async. Fixmailbox dependency on http * Only store number of messages not content in mailbox entity
This commit is contained in:
committed by
Paulus Schoutsen
parent
5696e38dd6
commit
d74f4eaf52
116
tests/components/mailbox/test_init.py
Normal file
116
tests/components/mailbox/test_init.py
Normal file
@@ -0,0 +1,116 @@
|
||||
"""The tests for the mailbox component."""
|
||||
import asyncio
|
||||
from hashlib import sha1
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
import homeassistant.components.mailbox as mailbox
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_http_client(hass, test_client):
|
||||
"""Start the Hass HTTP component."""
|
||||
config = {
|
||||
mailbox.DOMAIN: {
|
||||
'platform': 'demo'
|
||||
}
|
||||
}
|
||||
hass.loop.run_until_complete(
|
||||
async_setup_component(hass, mailbox.DOMAIN, config))
|
||||
return hass.loop.run_until_complete(test_client(hass.http.app))
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_platforms_from_mailbox(mock_http_client):
|
||||
"""Get platforms from mailbox."""
|
||||
url = "/api/mailbox/platforms"
|
||||
|
||||
req = yield from mock_http_client.get(url)
|
||||
assert req.status == 200
|
||||
result = yield from req.json()
|
||||
assert len(result) == 1 and "DemoMailbox" in result
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_messages_from_mailbox(mock_http_client):
|
||||
"""Get messages from mailbox."""
|
||||
url = "/api/mailbox/messages/DemoMailbox"
|
||||
|
||||
req = yield from mock_http_client.get(url)
|
||||
assert req.status == 200
|
||||
result = yield from req.json()
|
||||
assert len(result) == 10
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_media_from_mailbox(mock_http_client):
|
||||
"""Get audio from mailbox."""
|
||||
mp3sha = "3f67c4ea33b37d1710f772a26dd3fb43bb159d50"
|
||||
msgtxt = "This is recorded message # 1"
|
||||
msgsha = sha1(msgtxt.encode('utf-8')).hexdigest()
|
||||
|
||||
url = "/api/mailbox/media/DemoMailbox/%s" % (msgsha)
|
||||
req = yield from mock_http_client.get(url)
|
||||
assert req.status == 200
|
||||
data = yield from req.read()
|
||||
assert sha1(data).hexdigest() == mp3sha
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_delete_from_mailbox(mock_http_client):
|
||||
"""Get audio from mailbox."""
|
||||
msgtxt1 = "This is recorded message # 1"
|
||||
msgtxt2 = "This is recorded message # 2"
|
||||
msgsha1 = sha1(msgtxt1.encode('utf-8')).hexdigest()
|
||||
msgsha2 = sha1(msgtxt2.encode('utf-8')).hexdigest()
|
||||
|
||||
for msg in [msgsha1, msgsha2]:
|
||||
url = "/api/mailbox/delete/DemoMailbox/%s" % (msg)
|
||||
req = yield from mock_http_client.delete(url)
|
||||
assert req.status == 200
|
||||
|
||||
url = "/api/mailbox/messages/DemoMailbox"
|
||||
req = yield from mock_http_client.get(url)
|
||||
assert req.status == 200
|
||||
result = yield from req.json()
|
||||
assert len(result) == 8
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_messages_from_invalid_mailbox(mock_http_client):
|
||||
"""Get messages from mailbox."""
|
||||
url = "/api/mailbox/messages/mailbox.invalid_mailbox"
|
||||
|
||||
req = yield from mock_http_client.get(url)
|
||||
assert req.status == 404
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_media_from_invalid_mailbox(mock_http_client):
|
||||
"""Get messages from mailbox."""
|
||||
msgsha = "0000000000000000000000000000000000000000"
|
||||
url = "/api/mailbox/media/mailbox.invalid_mailbox/%s" % (msgsha)
|
||||
|
||||
req = yield from mock_http_client.get(url)
|
||||
assert req.status == 404
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_media_from_invalid_msgid(mock_http_client):
|
||||
"""Get messages from mailbox."""
|
||||
msgsha = "0000000000000000000000000000000000000000"
|
||||
url = "/api/mailbox/media/DemoMailbox/%s" % (msgsha)
|
||||
|
||||
req = yield from mock_http_client.get(url)
|
||||
assert req.status == 500
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_delete_from_invalid_mailbox(mock_http_client):
|
||||
"""Get audio from mailbox."""
|
||||
msgsha = "0000000000000000000000000000000000000000"
|
||||
url = "/api/mailbox/delete/mailbox.invalid_mailbox/%s" % (msgsha)
|
||||
|
||||
req = yield from mock_http_client.delete(url)
|
||||
assert req.status == 404
|
||||
Reference in New Issue
Block a user