Prevent more I/O in apns (#6413)

This commit is contained in:
Paulus Schoutsen 2017-03-04 19:57:04 -08:00 committed by GitHub
parent b939626497
commit 307514e3a7
2 changed files with 23 additions and 17 deletions

View file

@ -190,7 +190,6 @@ class ApnsNotificationService(BaseNotificationService):
has a tracking id specified. has a tracking id specified.
""" """
self.device_states[entity_id] = str(to_s.state) self.device_states[entity_id] = str(to_s.state)
return
def write_devices(self): def write_devices(self):
"""Write all known devices to file.""" """Write all known devices to file."""

View file

@ -1,7 +1,7 @@
"""The tests for the APNS component.""" """The tests for the APNS component."""
import io import io
import unittest import unittest
from unittest.mock import Mock, patch from unittest.mock import Mock, patch, mock_open
from apns2.errors import Unregistered from apns2.errors import Unregistered
import yaml import yaml
@ -23,6 +23,7 @@ CONFIG = {
} }
@patch('homeassistant.components.notify.apns.open', mock_open(), create=True)
class TestApns(unittest.TestCase): class TestApns(unittest.TestCase):
"""Test the APNS component.""" """Test the APNS component."""
@ -315,13 +316,21 @@ class TestApns(unittest.TestCase):
"""Test updating an existing device.""" """Test updating an existing device."""
send = mock_client.return_value.send_notification send = mock_client.return_value.send_notification
devices_path = self.hass.config.path('test_app_apns.yaml') yaml_file = {
with open(devices_path, 'w+') as out: 1234: {
out.write('1234: {name: test device 1, ' 'name': 'test device 1',
'tracking_device_id: tracking123}\n') 'tracking_device_id': 'tracking123',
out.write('5678: {name: test device 2, ' },
'tracking_device_id: tracking456}\n') 5678: {
'name': 'test device 2',
'tracking_device_id': 'tracking456',
},
}
with patch(
'homeassistant.components.notify.apns.load_yaml_config_file',
Mock(return_value=yaml_file)), \
patch('os.path.isfile', Mock(return_value=True)):
notify_service = apns.ApnsNotificationService( notify_service = apns.ApnsNotificationService(
self.hass, self.hass,
'test_app', 'test_app',
@ -335,8 +344,6 @@ class TestApns(unittest.TestCase):
State('device_tracker.tracking456', None), State('device_tracker.tracking456', None),
State('device_tracker.tracking456', 'home')) State('device_tracker.tracking456', 'home'))
self.hass.block_till_done()
notify_service.send_message(message='Hello', target='home') notify_service.send_message(message='Hello', target='home')
self.assertTrue(send.called) self.assertTrue(send.called)