Move imports in apns component (#27804)

* Move imports in apns component

* fixed apns tests
pull/27842/head
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."""
import logging
from apns2.client import APNsClient
from apns2.errors import Unregistered
from apns2.payload import Payload
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 (
ATTR_DATA,
ATTR_TARGET,
@ -16,6 +13,11 @@ from homeassistant.components.notify import (
PLATFORM_SCHEMA,
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"
CONF_CERTFILE = "cert_file"
@ -213,9 +215,6 @@ class ApnsNotificationService(BaseNotificationService):
def send_message(self, message=None, **kwargs):
"""Send push message to registered devices."""
from apns2.client import APNsClient
from apns2.payload import Payload
from apns2.errors import Unregistered
apns = APNsClient(
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 "tracking456" == test_device_2.tracking_device_id
@patch("apns2.client.APNsClient")
@patch("homeassistant.components.apns.notify.APNsClient")
def test_send(self, mock_client):
"""Test updating an existing device."""
send = mock_client.return_value.send_notification
@ -274,7 +274,7 @@ class TestApns(unittest.TestCase):
assert "test.mp3" == payload.sound
assert "testing" == payload.category
@patch("apns2.client.APNsClient")
@patch("homeassistant.components.apns.notify.APNsClient")
def test_send_when_disabled(self, mock_client):
"""Test updating an existing device."""
send = mock_client.return_value.send_notification
@ -299,7 +299,7 @@ class TestApns(unittest.TestCase):
assert not send.called
@patch("apns2.client.APNsClient")
@patch("homeassistant.components.apns.notify.APNsClient")
def test_send_with_state(self, mock_client):
"""Test updating an existing device."""
send = mock_client.return_value.send_notification
@ -334,7 +334,7 @@ class TestApns(unittest.TestCase):
assert "5678" == target
assert "Hello" == payload.alert
@patch("apns2.client.APNsClient")
@patch("homeassistant.components.apns.notify.APNsClient")
@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."""