healthchecks_healthchecks/hc/lib/tests/test_statsd.py
2024-06-27 11:03:29 +03:00

31 lines
986 B
Python

from __future__ import annotations
from unittest import TestCase
from django.test.utils import override_settings
from statsd.client.udp import StatsClient
from hc.lib.statsd import NoopClient, get_client
class StatsdTestCase(TestCase):
@override_settings(STATSD_HOST="localhost")
def test_it_initializes_udp_client(self) -> None:
client = get_client()
self.assertTrue(isinstance(client, StatsClient))
self.assertEqual(client._addr, ("127.0.0.1", 8125))
client.close()
@override_settings(STATSD_HOST="localhost:1234")
def test_it_parses_port(self) -> None:
client = get_client()
self.assertTrue(isinstance(client, StatsClient))
self.assertEqual(client._addr, ("127.0.0.1", 1234))
client.close()
@override_settings(STATSD_HOST=None)
def test_it_initializes_noop_client(self) -> None:
client = get_client()
self.assertTrue(isinstance(client, NoopClient))
client.close()