async def test_disable_when_unregistered(mock_write, mock_client, hass): """Test disabling a device when it is unregistered.""" send = mock_client.return_value.send_notification send.side_effect = Unregistered() yaml_file = { 1234: {"name": "test device 1", "tracking_device_id": "tracking123"}, 5678: {"name": "test device 2", "tracking_device_id": "tracking456"}, } written_devices = [] def fake_write(_out, device): """Fake write_device.""" written_devices.append(device) mock_write.side_effect = fake_write with patch( "homeassistant.components.apns.notify.load_yaml_config_file", Mock(return_value=yaml_file), ): await _setup_notify(hass) assert await hass.services.async_call( "notify", "test_app", {"message": "Hello"}, blocking=True ) devices = {dev.push_id: dev for dev in written_devices} test_device_1 = devices.get("1234") assert test_device_1 is not None assert test_device_1.disabled is True
def test_disable_when_unregistered(self, mock_client): """Test disabling a device when it is unregistered.""" send = mock_client.return_value.send_notification send.side_effect = Unregistered() devices_path = self.hass.config.path('test_app_apns.yaml') with open(devices_path, 'w+') as out: out.write('1234: {name: test device 1}\n') self._setup_notify() self.assertTrue( self.hass.services.call('notify', 'test_app', {'message': 'Hello'}, blocking=True)) devices = { str(key): value for (key, value) in load_yaml_config_file(devices_path).items() } test_device_1 = devices.get('1234') self.assertIsNotNone(test_device_1) self.assertEqual(True, test_device_1.get('disabled')) os.remove(devices_path)
def test_disable_when_unregistered(self, mock_client): """Test disabling a device when it is unregistered.""" send = mock_client.return_value.send_notification send.side_effect = Unregistered() config = { 'notify': { 'platform': 'apns', 'name': 'test_app', 'topic': 'testapp.appname', 'cert_file': 'test_app.pem' } } hass = get_test_home_assistant() devices_path = hass.config.path('test_app_apns.yaml') with open(devices_path, 'w+') as out: out.write('1234: {name: test device 1}\n') notify.setup(hass, config) self.assertTrue(hass.services.call('notify', 'test_app', {'message': 'Hello'}, blocking=True)) devices = {str(key): value for (key, value) in load_yaml_config_file(devices_path).items()} test_device_1 = devices.get('1234') self.assertIsNotNone(test_device_1) self.assertEqual(True, test_device_1.get('disabled')) os.remove(devices_path)
def test_disable_when_unregistered(self, mock_write, mock_client): """Test disabling a device when it is unregistered.""" from apns2.errors import Unregistered send = mock_client.return_value.send_notification send.side_effect = Unregistered() yaml_file = { 1234: { 'name': 'test device 1', 'tracking_device_id': 'tracking123', }, 5678: { 'name': 'test device 2', 'tracking_device_id': 'tracking456', }, } written_devices = [] def fake_write(_out, device): """Fake write_device.""" written_devices.append(device) mock_write.side_effect = fake_write with patch( 'homeassistant.components.notify.apns.load_yaml_config_file', Mock(return_value=yaml_file)): self._setup_notify() self.assertTrue(self.hass.services.call('notify', 'test_app', {'message': 'Hello'}, blocking=True)) devices = {dev.push_id: dev for dev in written_devices} test_device_1 = devices.get('1234') self.assertIsNotNone(test_device_1) self.assertEqual(True, test_device_1.disabled)