Great migration notify (#22406)
* Move notify platforms into components * Move notify tests * Fix notify tests * More fixes * Update requirements * Update .coveragerc * Run gen reqs
This commit is contained in:
1 parent
92457ca5ca
commit
7741ec4d5a
105 files changed
+653
-582
No files matched your search
@@ -0,0 +1 @@
|
||||
"""Tests for the apns component."""
|
||||
@@ -8,7 +8,7 @@ import yaml
|
||||
|
||||
import homeassistant.components.notify as notify
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.components.notify import apns
|
||||
import homeassistant.components.apns.notify as apns
|
||||
from homeassistant.core import State
|
||||
|
||||
from tests.common import assert_setup_component, get_test_home_assistant
|
||||
@@ -23,7 +23,7 @@ CONFIG = {
|
||||
}
|
||||
|
||||
|
||||
@patch('homeassistant.components.notify.apns.open', mock_open(), create=True)
|
||||
@patch('homeassistant.components.apns.notify.open', mock_open(), create=True)
|
||||
class TestApns(unittest.TestCase):
|
||||
"""Test the APNS component."""
|
||||
|
||||
@@ -102,7 +102,7 @@ class TestApns(unittest.TestCase):
|
||||
assert setup_component(self.hass, notify.DOMAIN, config)
|
||||
assert not handle_config[notify.DOMAIN]
|
||||
|
||||
@patch('homeassistant.components.notify.apns._write_device')
|
||||
@patch('homeassistant.components.apns.notify._write_device')
|
||||
def test_register_new_device(self, mock_write):
|
||||
"""Test registering a new device with a name."""
|
||||
yaml_file = {5678: {'name': 'test device 2'}}
|
||||
@@ -116,7 +116,7 @@ class TestApns(unittest.TestCase):
|
||||
mock_write.side_effect = fake_write
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.notify.apns.load_yaml_config_file',
|
||||
'homeassistant.components.apns.notify.load_yaml_config_file',
|
||||
Mock(return_value=yaml_file)):
|
||||
self._setup_notify()
|
||||
|
||||
@@ -128,7 +128,7 @@ class TestApns(unittest.TestCase):
|
||||
assert len(written_devices) == 1
|
||||
assert written_devices[0].name == 'test device'
|
||||
|
||||
@patch('homeassistant.components.notify.apns._write_device')
|
||||
@patch('homeassistant.components.apns.notify._write_device')
|
||||
def test_register_device_without_name(self, mock_write):
|
||||
"""Test registering a without a name."""
|
||||
yaml_file = {
|
||||
@@ -151,7 +151,7 @@ class TestApns(unittest.TestCase):
|
||||
mock_write.side_effect = fake_write
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.notify.apns.load_yaml_config_file',
|
||||
'homeassistant.components.apns.notify.load_yaml_config_file',
|
||||
Mock(return_value=yaml_file)):
|
||||
self._setup_notify()
|
||||
|
||||
@@ -166,7 +166,7 @@ class TestApns(unittest.TestCase):
|
||||
assert test_device is not None
|
||||
assert test_device.name is None
|
||||
|
||||
@patch('homeassistant.components.notify.apns._write_device')
|
||||
@patch('homeassistant.components.apns.notify._write_device')
|
||||
def test_update_existing_device(self, mock_write):
|
||||
"""Test updating an existing device."""
|
||||
yaml_file = {
|
||||
@@ -187,7 +187,7 @@ class TestApns(unittest.TestCase):
|
||||
mock_write.side_effect = fake_write
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.notify.apns.load_yaml_config_file',
|
||||
'homeassistant.components.apns.notify.load_yaml_config_file',
|
||||
Mock(return_value=yaml_file)):
|
||||
self._setup_notify()
|
||||
|
||||
@@ -206,7 +206,7 @@ class TestApns(unittest.TestCase):
|
||||
|
||||
assert 'updated device 1' == test_device_1.name
|
||||
|
||||
@patch('homeassistant.components.notify.apns._write_device')
|
||||
@patch('homeassistant.components.apns.notify._write_device')
|
||||
def test_update_existing_device_with_tracking_id(self, mock_write):
|
||||
"""Test updating an existing device that has a tracking id."""
|
||||
yaml_file = {
|
||||
@@ -229,7 +229,7 @@ class TestApns(unittest.TestCase):
|
||||
mock_write.side_effect = fake_write
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.notify.apns.load_yaml_config_file',
|
||||
'homeassistant.components.apns.notify.load_yaml_config_file',
|
||||
Mock(return_value=yaml_file)):
|
||||
self._setup_notify()
|
||||
|
||||
@@ -259,7 +259,7 @@ class TestApns(unittest.TestCase):
|
||||
yaml_file = {1234: {'name': 'test device 1'}}
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.notify.apns.load_yaml_config_file',
|
||||
'homeassistant.components.apns.notify.load_yaml_config_file',
|
||||
Mock(return_value=yaml_file)):
|
||||
self._setup_notify()
|
||||
|
||||
@@ -294,7 +294,7 @@ class TestApns(unittest.TestCase):
|
||||
}}
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.notify.apns.load_yaml_config_file',
|
||||
'homeassistant.components.apns.notify.load_yaml_config_file',
|
||||
Mock(return_value=yaml_file)):
|
||||
self._setup_notify()
|
||||
|
||||
@@ -325,7 +325,7 @@ class TestApns(unittest.TestCase):
|
||||
}
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.notify.apns.load_yaml_config_file',
|
||||
'homeassistant.components.apns.notify.load_yaml_config_file',
|
||||
Mock(return_value=yaml_file)), \
|
||||
patch('os.path.isfile', Mock(return_value=True)):
|
||||
notify_service = apns.ApnsNotificationService(
|
||||
@@ -353,7 +353,7 @@ class TestApns(unittest.TestCase):
|
||||
assert 'Hello' == payload.alert
|
||||
|
||||
@patch('apns2.client.APNsClient')
|
||||
@patch('homeassistant.components.notify.apns._write_device')
|
||||
@patch('homeassistant.components.apns.notify._write_device')
|
||||
def test_disable_when_unregistered(self, mock_write, mock_client):
|
||||
"""Test disabling a device when it is unregistered."""
|
||||
send = mock_client.return_value.send_notification
|
||||
@@ -379,7 +379,7 @@ class TestApns(unittest.TestCase):
|
||||
mock_write.side_effect = fake_write
|
||||
|
||||
with patch(
|
||||
'homeassistant.components.notify.apns.load_yaml_config_file',
|
||||
'homeassistant.components.apns.notify.load_yaml_config_file',
|
||||
Mock(return_value=yaml_file)):
|
||||
self._setup_notify()
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ class TestCommandLine(unittest.TestCase):
|
||||
# the echo command adds a line break
|
||||
assert fil.read() == "{}\n".format(message)
|
||||
|
||||
@patch('homeassistant.components.notify.command_line._LOGGER.error')
|
||||
@patch('homeassistant.components.command_line.notify._LOGGER.error')
|
||||
def test_error_for_none_zero_exit_code(self, mock_error):
|
||||
"""Test if an error is logged for non zero exit codes."""
|
||||
with assert_setup_component(1) as handle_config:
|
||||
@@ -7,7 +7,7 @@ import voluptuous as vol
|
||||
|
||||
import homeassistant.components.notify as notify
|
||||
from homeassistant.setup import setup_component
|
||||
from homeassistant.components.notify import demo
|
||||
import homeassistant.components.demo.notify as demo
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import discovery, script
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||
"""Test setup."""
|
||||
self._setup_notify()
|
||||
|
||||
@patch('homeassistant.components.notify.demo.get_service', autospec=True)
|
||||
@patch('homeassistant.components.demo.notify.get_service', autospec=True)
|
||||
def test_no_notify_service(self, mock_demo_get_service):
|
||||
"""Test missing platform notify service instance."""
|
||||
mock_demo_get_service.return_value = None
|
||||
@@ -63,7 +63,7 @@ class TestNotifyDemo(unittest.TestCase):
|
||||
['ERROR:homeassistant.components.notify:'
|
||||
'Failed to initialize notification service demo']
|
||||
|
||||
@patch('homeassistant.components.notify.demo.get_service', autospec=True)
|
||||
@patch('homeassistant.components.demo.notify.get_service', autospec=True)
|
||||
def test_discover_notify(self, mock_demo_get_service):
|
||||
"""Test discovery of notify demo platform."""
|
||||
assert notify.DOMAIN not in self.hass.config.components
|
||||
@@ -0,0 +1 @@
|
||||
"""Tests for the facebook component."""
|
||||
@@ -2,7 +2,8 @@
|
||||
import unittest
|
||||
import requests_mock
|
||||
|
||||
import homeassistant.components.notify.facebook as facebook
|
||||
# import homeassistant.components.facebook as facebook
|
||||
import homeassistant.components.facebook.notify as facebook
|
||||
|
||||
|
||||
class TestFacebook(unittest.TestCase):
|
||||
@@ -52,9 +52,9 @@ class TestNotifyFile(unittest.TestCase):
|
||||
|
||||
m_open = mock_open()
|
||||
with patch(
|
||||
'homeassistant.components.notify.file.open',
|
||||
'homeassistant.components.file.notify.open',
|
||||
m_open, create=True
|
||||
), patch('homeassistant.components.notify.file.os.stat') as mock_st, \
|
||||
), patch('homeassistant.components.file.notify.os.stat') as mock_st, \
|
||||
patch('homeassistant.util.dt.utcnow',
|
||||
return_value=dt_util.utcnow()):
|
||||
|
||||
@@ -4,7 +4,8 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
from homeassistant.setup import setup_component
|
||||
import homeassistant.components.notify as notify
|
||||
from homeassistant.components.notify import group, demo
|
||||
import homeassistant.components.group.notify as group
|
||||
import homeassistant.components.demo.notify as demo
|
||||
from homeassistant.util.async_ import run_coroutine_threadsafe
|
||||
|
||||
from tests.common import assert_setup_component, get_test_home_assistant
|
||||
@@ -0,0 +1 @@
|
||||
"""Tests for the homematic component."""
|
||||
File renamed without changes.
@@ -0,0 +1 @@
|
||||
"""Tests for the html5 component."""
|
||||
@@ -5,7 +5,7 @@ from aiohttp.hdrs import AUTHORIZATION
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.components.notify import html5
|
||||
import homeassistant.components.html5.notify as html5
|
||||
|
||||
CONFIG_FILE = 'file.conf'
|
||||
|
||||
@@ -54,7 +54,7 @@ async def mock_client(hass, hass_client, registrations=None):
|
||||
if registrations is None:
|
||||
registrations = {}
|
||||
|
||||
with patch('homeassistant.components.notify.html5._load_config',
|
||||
with patch('homeassistant.components.html5.notify._load_config',
|
||||
return_value=registrations):
|
||||
await async_setup_component(hass, 'notify', {
|
||||
'notify': {
|
||||
@@ -189,7 +189,7 @@ async def test_registering_new_device_view(hass, hass_client):
|
||||
"""Test that the HTML view works."""
|
||||
client = await mock_client(hass, hass_client)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
with patch('homeassistant.components.html5.notify.save_json') as mock_save:
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_1))
|
||||
|
||||
assert resp.status == 200
|
||||
@@ -206,7 +206,7 @@ async def test_registering_new_device_view_with_name(hass, hass_client):
|
||||
SUB_WITH_NAME = SUBSCRIPTION_1.copy()
|
||||
SUB_WITH_NAME['name'] = 'test device'
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
with patch('homeassistant.components.html5.notify.save_json') as mock_save:
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps(SUB_WITH_NAME))
|
||||
|
||||
assert resp.status == 200
|
||||
@@ -220,7 +220,7 @@ async def test_registering_new_device_expiration_view(hass, hass_client):
|
||||
"""Test that the HTML view works."""
|
||||
client = await mock_client(hass, hass_client)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
with patch('homeassistant.components.html5.notify.save_json') as mock_save:
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_4))
|
||||
|
||||
assert resp.status == 200
|
||||
@@ -234,7 +234,7 @@ async def test_registering_new_device_fails_view(hass, hass_client):
|
||||
registrations = {}
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json',
|
||||
with patch('homeassistant.components.html5.notify.save_json',
|
||||
side_effect=HomeAssistantError()):
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_4))
|
||||
|
||||
@@ -247,7 +247,7 @@ async def test_registering_existing_device_view(hass, hass_client):
|
||||
registrations = {}
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
with patch('homeassistant.components.html5.notify.save_json') as mock_save:
|
||||
await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_1))
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_4))
|
||||
|
||||
@@ -268,7 +268,7 @@ async def test_registering_existing_device_view_with_name(hass, hass_client):
|
||||
SUB_WITH_NAME = SUBSCRIPTION_1.copy()
|
||||
SUB_WITH_NAME['name'] = 'test device'
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
with patch('homeassistant.components.html5.notify.save_json') as mock_save:
|
||||
await client.post(REGISTER_URL, data=json.dumps(SUB_WITH_NAME))
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_4))
|
||||
|
||||
@@ -286,7 +286,7 @@ async def test_registering_existing_device_fails_view(hass, hass_client):
|
||||
registrations = {}
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
with patch('homeassistant.components.html5.notify.save_json') as mock_save:
|
||||
await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_1))
|
||||
mock_save.side_effect = HomeAssistantError
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps(SUBSCRIPTION_4))
|
||||
@@ -312,7 +312,7 @@ async def test_registering_new_device_validation(hass, hass_client):
|
||||
}))
|
||||
assert resp.status == 400
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json',
|
||||
with patch('homeassistant.components.html5.notify.save_json',
|
||||
return_value=False):
|
||||
resp = await client.post(REGISTER_URL, data=json.dumps({
|
||||
'browser': 'chrome',
|
||||
@@ -329,7 +329,7 @@ async def test_unregistering_device_view(hass, hass_client):
|
||||
}
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
with patch('homeassistant.components.html5.notify.save_json') as mock_save:
|
||||
resp = await client.delete(REGISTER_URL, data=json.dumps({
|
||||
'subscription': SUBSCRIPTION_1['subscription'],
|
||||
}))
|
||||
@@ -347,7 +347,7 @@ async def test_unregister_device_view_handle_unknown_subscription(
|
||||
registrations = {}
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json') as mock_save:
|
||||
with patch('homeassistant.components.html5.notify.save_json') as mock_save:
|
||||
resp = await client.delete(REGISTER_URL, data=json.dumps({
|
||||
'subscription': SUBSCRIPTION_3['subscription']
|
||||
}))
|
||||
@@ -366,7 +366,7 @@ async def test_unregistering_device_view_handles_save_error(
|
||||
}
|
||||
client = await mock_client(hass, hass_client, registrations)
|
||||
|
||||
with patch('homeassistant.components.notify.html5.save_json',
|
||||
with patch('homeassistant.components.html5.notify.save_json',
|
||||
side_effect=HomeAssistantError()):
|
||||
resp = await client.delete(REGISTER_URL, data=json.dumps({
|
||||
'subscription': SUBSCRIPTION_1['subscription'],
|
||||
@@ -0,0 +1 @@
|
||||
"""Tests for the pushbullet component."""
|
||||
File renamed without changes.
@@ -0,0 +1 @@
|
||||
"""Tests for the smtp component."""
|
||||
@@ -2,13 +2,13 @@
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant.components.notify import smtp
|
||||
from homeassistant.components.smtp.notify import MailNotificationService
|
||||
|
||||
from tests.common import get_test_home_assistant
|
||||
import re
|
||||
|
||||
|
||||
class MockSMTP(smtp.MailNotificationService):
|
||||
class MockSMTP(MailNotificationService):
|
||||
"""Test SMTP object that doesn't need a working server."""
|
||||
|
||||
def _send_email(self, msg):
|
||||
@@ -0,0 +1 @@
|
||||
"""Tests for the yessssms component."""
|
||||
+10
-10
@@ -1,7 +1,7 @@
|
||||
"""The tests for the notify yessssms platform."""
|
||||
import unittest
|
||||
import requests_mock
|
||||
from homeassistant.components.notify import yessssms
|
||||
import homeassistant.components.yessssms.notify as yessssms
|
||||
|
||||
|
||||
class TestNotifyYesssSMS(unittest.TestCase):
|
||||
@@ -28,7 +28,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
with self.assertLogs("homeassistant.components.notify",
|
||||
with self.assertLogs("homeassistant.components.yessssms.notify",
|
||||
level='ERROR'):
|
||||
self.yessssms.send_message(message)
|
||||
self.assertTrue(mock.called)
|
||||
@@ -37,7 +37,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
def test_empty_message_error(self):
|
||||
"""Test for an empty SMS message error."""
|
||||
message = ""
|
||||
with self.assertLogs("homeassistant.components.notify",
|
||||
with self.assertLogs("homeassistant.components.yessssms.notify",
|
||||
level='ERROR'):
|
||||
self.yessssms.send_message(message)
|
||||
|
||||
@@ -54,7 +54,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
with self.assertLogs("homeassistant.components.notify",
|
||||
with self.assertLogs("homeassistant.components.yessssms.notify",
|
||||
level='ERROR'):
|
||||
self.yessssms.send_message(message)
|
||||
self.assertTrue(mock.called)
|
||||
@@ -71,7 +71,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
with self.assertLogs("homeassistant.components.notify",
|
||||
with self.assertLogs("homeassistant.components.yessssms.notify",
|
||||
level='ERROR'):
|
||||
self.yessssms.send_message(message)
|
||||
self.assertTrue(mock.called)
|
||||
@@ -83,7 +83,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
# pylint: disable=protected-access
|
||||
self.yessssms.yesss._suspended = True
|
||||
|
||||
with self.assertLogs("homeassistant.components.notify",
|
||||
with self.assertLogs("homeassistant.components.yessssms.notify",
|
||||
level='ERROR') as context:
|
||||
self.yessssms.send_message(message)
|
||||
self.assertIn("Account is suspended, cannot send SMS.",
|
||||
@@ -124,7 +124,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
with self.assertLogs("homeassistant.components.notify",
|
||||
with self.assertLogs("homeassistant.components.yessssms.notify",
|
||||
level='INFO') as context:
|
||||
self.yessssms.send_message(message)
|
||||
self.assertIn("SMS sent", context.output[0])
|
||||
@@ -143,7 +143,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
# pylint: disable=protected-access
|
||||
self.yessssms._recipient = ""
|
||||
|
||||
with self.assertLogs("homeassistant.components.notify",
|
||||
with self.assertLogs("homeassistant.components.yessssms.notify",
|
||||
level='ERROR') as context:
|
||||
self.yessssms.send_message(message)
|
||||
|
||||
@@ -179,7 +179,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
with self.assertLogs("homeassistant.components.notify",
|
||||
with self.assertLogs("homeassistant.components.yessssms.notify",
|
||||
level='ERROR') as context:
|
||||
self.yessssms.send_message(message)
|
||||
|
||||
@@ -199,7 +199,7 @@ class TestNotifyYesssSMS(unittest.TestCase):
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
with self.assertLogs("homeassistant.components.notify",
|
||||
with self.assertLogs("homeassistant.components.yessssms.notify",
|
||||
level='ERROR') as context:
|
||||
self.yessssms.send_message(message)
|
||||
|
||||
Reference in new issue
Block a user