Exemplo n.º 1
0
    def test_get_statsd_client(self) -> None:
        with patch.object(current_app, 'config') as mock_config, \
                patch.object(StatsClient, '__init__', return_value=None) as mock_statsd_init:
            mock_config.return_value.single.return_value = True

            statsd_client1 = _get_statsd_client(prefix='foo')
            self.assertIsNotNone(statsd_client1)
            statsd_client2 = _get_statsd_client(prefix='foo')
            self.assertIsNotNone(statsd_client2)
            self.assertEqual(statsd_client1, statsd_client2)

            self.assertEqual(mock_statsd_init.call_count, 1)

            statsd_client3 = _get_statsd_client(prefix='bar')
            self.assertIsNotNone(statsd_client3)
            statsd_client4 = _get_statsd_client(prefix='bar')
            self.assertIsNotNone(statsd_client4)
            self.assertEqual(statsd_client3, statsd_client4)

            self.assertNotEqual(statsd_client1, statsd_client3)
            self.assertEqual(mock_statsd_init.call_count, 2)
Exemplo n.º 2
0
 def test_no_statsd_client(self) -> None:
     with patch.object(StatsClient, '__init__'):
         statsd_client = _get_statsd_client(prefix='foo')
         self.assertIsNone(statsd_client)