'Test registering a new device with a name.'

@patch('homeassistant.components.notify.apns._write_device')
def test_register_new_device(self, mock_write):

    yaml_file = {5678: {'name': 'test    device    2'}}
    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.DOMAIN, 'apns_test_app', {'push_id': '1234', 'name': 'test    device'}, blocking=True))
    assert (len(written_devices) == 1)
    assert (written_devices[0].name == 'test    device')
