'Test disabling a device when it is unregistered.'

@patch('apns2.client.APNsClient')
@patch('homeassistant.components.notify.apns._write_device')
def test_disable_when_unregistered(self, mock_write, mock_client):

    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)
