Exemple #1
0
    def test_send_with_state(self, mock_client):
        """Test updating an existing device."""
        send = mock_client.return_value.send_notification

        yaml_file = {
            1234: {"name": "test device 1", "tracking_device_id": "tracking123"},
            5678: {"name": "test device 2", "tracking_device_id": "tracking456"},
        }

        with patch(
            "homeassistant.components.apns.notify.load_yaml_config_file",
            Mock(return_value=yaml_file),
        ), patch("os.path.isfile", Mock(return_value=True)):
            notify_service = apns.ApnsNotificationService(
                self.hass, "test_app", "testapp.appname", False, "test_app.pem"
            )

        notify_service.device_state_changed_listener(
            "device_tracker.tracking456",
            State("device_tracker.tracking456", None),
            State("device_tracker.tracking456", "home"),
        )

        notify_service.send_message(message="Hello", target="home")

        assert send.called
        assert 1 == len(send.mock_calls)

        target = send.mock_calls[0][1][0]
        payload = send.mock_calls[0][1][1]

        assert "5678" == target
        assert "Hello" == payload.alert
Exemple #2
0
    def test_send_with_state(self, mock_client):
        """Test updating an existing device."""
        send = mock_client.return_value.send_notification

        yaml_file = {
            1234: {
                'name': 'test device 1',
                'tracking_device_id': 'tracking123',
            },
            5678: {
                'name': 'test device 2',
                'tracking_device_id': 'tracking456',
            },
        }

        with patch(
            'homeassistant.components.apns.notify.load_yaml_config_file',
                Mock(return_value=yaml_file)), \
                patch('os.path.isfile', Mock(return_value=True)):
            notify_service = apns.ApnsNotificationService(
                self.hass, 'test_app', 'testapp.appname', False,
                'test_app.pem')

        notify_service.device_state_changed_listener(
            'device_tracker.tracking456',
            State('device_tracker.tracking456', None),
            State('device_tracker.tracking456', 'home'))

        notify_service.send_message(message='Hello', target='home')

        assert send.called
        assert 1 == len(send.mock_calls)

        target = send.mock_calls[0][1][0]
        payload = send.mock_calls[0][1][1]

        assert '5678' == target
        assert 'Hello' == payload.alert