def test_should_log_but_not_throw_if_socket_errors(app, mocker):
    stats_client = NotifyStatsClient('localhost', 8125, '')
    mocker.patch.object(stats_client, "_sock")
    stats_client._sock.sendto = Mock(side_effect=Exception('Mock Exception'))
    mock_logger = mocker.patch('flask.Flask.logger')

    stats_client._send('data')
    mock_logger.warning.assert_called_with('Error sending statsd metric: Mock Exception')
def test_should_not_attempt_to_send_if_cache_contains_none(app, mocker):
    stats_client = NotifyStatsClient('localhost', 8125, '')
    mock_sock = mocker.patch.object(stats_client, "_sock")
    mock_cached_host = mocker.patch.object(stats_client, '_cached_host', return_value=None)

    stats_client._send('data')

    mock_cached_host.assert_called_once_with()
    assert mock_sock.called is False