stats_logger_tests.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Unit tests for Superset"""
  18. from unittest import TestCase
  19. from unittest.mock import Mock, patch
  20. from superset.stats_logger import StatsdStatsLogger
  21. class StatsdStatsLoggerTest(TestCase):
  22. def verify_client_calls(self, logger, client):
  23. logger.incr("foo1")
  24. client.incr.assert_called_once()
  25. client.incr.assert_called_with("foo1")
  26. logger.decr("foo2")
  27. client.decr.assert_called_once()
  28. client.decr.assert_called_with("foo2")
  29. logger.gauge("foo3")
  30. client.gauge.assert_called_once()
  31. client.gauge.assert_called_with("foo3")
  32. logger.timing("foo4", 1.234)
  33. client.timing.assert_called_once()
  34. client.timing.assert_called_with("foo4", 1.234)
  35. def test_init_with_statsd_client(self):
  36. client = Mock()
  37. stats_logger = StatsdStatsLogger(statsd_client=client)
  38. self.verify_client_calls(stats_logger, client)
  39. def test_init_with_params(self):
  40. with patch("superset.stats_logger.StatsClient") as MockStatsdClient:
  41. mock_client = MockStatsdClient.return_value
  42. stats_logger = StatsdStatsLogger()
  43. self.verify_client_calls(stats_logger, mock_client)