Move imports in apns component (#27804)

* Move imports in apns component

* fixed apns tests
This commit is contained in:
bouni 2019-10-18 07:13:29 +02:00 committed by Paulus Schoutsen
parent 5cb145f588
commit 511766cb06
2 changed files with 12 additions and 13 deletions

View file

@ -1,14 +1,11 @@
"""APNS Notification platform.""" """APNS Notification platform."""
import logging import logging
from apns2.client import APNsClient
from apns2.errors import Unregistered
from apns2.payload import Payload
import voluptuous as vol import voluptuous as vol
from homeassistant.config import load_yaml_config_file
from homeassistant.const import ATTR_NAME, CONF_NAME, CONF_PLATFORM
from homeassistant.helpers import template as template_helper
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import track_state_change
from homeassistant.components.notify import ( from homeassistant.components.notify import (
ATTR_DATA, ATTR_DATA,
ATTR_TARGET, ATTR_TARGET,
@ -16,6 +13,11 @@ from homeassistant.components.notify import (
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
BaseNotificationService, BaseNotificationService,
) )
from homeassistant.config import load_yaml_config_file
from homeassistant.const import ATTR_NAME, CONF_NAME, CONF_PLATFORM
from homeassistant.helpers import template as template_helper
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import track_state_change
APNS_DEVICES = "apns.yaml" APNS_DEVICES = "apns.yaml"
CONF_CERTFILE = "cert_file" CONF_CERTFILE = "cert_file"
@ -213,9 +215,6 @@ class ApnsNotificationService(BaseNotificationService):
def send_message(self, message=None, **kwargs): def send_message(self, message=None, **kwargs):
"""Send push message to registered devices.""" """Send push message to registered devices."""
from apns2.client import APNsClient
from apns2.payload import Payload
from apns2.errors import Unregistered
apns = APNsClient( apns = APNsClient(
self.certificate, use_sandbox=self.sandbox, use_alternative_port=False self.certificate, use_sandbox=self.sandbox, use_alternative_port=False

View file

@ -239,7 +239,7 @@ class TestApns(unittest.TestCase):
assert "tracking123" == test_device_1.tracking_device_id assert "tracking123" == test_device_1.tracking_device_id
assert "tracking456" == test_device_2.tracking_device_id assert "tracking456" == test_device_2.tracking_device_id
@patch("apns2.client.APNsClient") @patch("homeassistant.components.apns.notify.APNsClient")
def test_send(self, mock_client): def test_send(self, mock_client):
"""Test updating an existing device.""" """Test updating an existing device."""
send = mock_client.return_value.send_notification send = mock_client.return_value.send_notification
@ -274,7 +274,7 @@ class TestApns(unittest.TestCase):
assert "test.mp3" == payload.sound assert "test.mp3" == payload.sound
assert "testing" == payload.category assert "testing" == payload.category
@patch("apns2.client.APNsClient") @patch("homeassistant.components.apns.notify.APNsClient")
def test_send_when_disabled(self, mock_client): def test_send_when_disabled(self, mock_client):
"""Test updating an existing device.""" """Test updating an existing device."""
send = mock_client.return_value.send_notification send = mock_client.return_value.send_notification
@ -299,7 +299,7 @@ class TestApns(unittest.TestCase):
assert not send.called assert not send.called
@patch("apns2.client.APNsClient") @patch("homeassistant.components.apns.notify.APNsClient")
def test_send_with_state(self, mock_client): def test_send_with_state(self, mock_client):
"""Test updating an existing device.""" """Test updating an existing device."""
send = mock_client.return_value.send_notification send = mock_client.return_value.send_notification
@ -334,7 +334,7 @@ class TestApns(unittest.TestCase):
assert "5678" == target assert "5678" == target
assert "Hello" == payload.alert assert "Hello" == payload.alert
@patch("apns2.client.APNsClient") @patch("homeassistant.components.apns.notify.APNsClient")
@patch("homeassistant.components.apns.notify._write_device") @patch("homeassistant.components.apns.notify._write_device")
def test_disable_when_unregistered(self, mock_write, mock_client): def test_disable_when_unregistered(self, mock_write, mock_client):
"""Test disabling a device when it is unregistered.""" """Test disabling a device when it is unregistered."""