def test_should_cache_none_if_dns_fails(app, mocker):
    stats_client = NotifyStatsClient('exporter.apps.internal', 8125, '')

    with patch.object(stats_client, '_resolve', side_effect=Exception('DNS No Worky')) as mock_dns_lookup:
        assert stats_client._cached_host() is None
        mock_dns_lookup.assert_called_once_with('exporter.apps.internal')

    with patch.object(stats_client, '_resolve') as mock_dns_lookup:
        assert stats_client._cached_host() is None
        assert mock_dns_lookup.called is False
def test_should_cache_dns(app, mocker):
    stats_client = NotifyStatsClient('exporter.apps.internal', 8125, '')

    with patch.object(stats_client, '_resolve', return_value='1.2.3.4') as mock_dns_lookup:
        assert stats_client._cached_host() == '1.2.3.4'
        mock_dns_lookup.assert_called_once_with('exporter.apps.internal')

    with patch.object(stats_client, '_resolve') as mock_dns_lookup:
        assert stats_client._cached_host() == '1.2.3.4'
        assert mock_dns_lookup.called is False
Esempio n. 3
0
def test_should_manage_dns(app, mocker):
    stats_client = NotifyStatsClient('exporter.apps.internal', 8125, '')

    with patch.object(stats_client, '_resolve', return_value='1.2.3.4'):
        assert stats_client._cached_host() == '1.2.3.4'