diff --git a/auditmiddleware/tests/unit/base.py b/auditmiddleware/tests/unit/base.py index 62df611..b040857 100644 --- a/auditmiddleware/tests/unit/base.py +++ b/auditmiddleware/tests/unit/base.py @@ -105,19 +105,27 @@ def setUp(self): self.username = "test user " + str(user_counter) user_counter += 1 - patcher = mock.patch('datadog.dogstatsd.DogStatsd._report') - self.statsd_report_mock = patcher.start() - self.addCleanup(patcher.stop) + inc_patcher = mock.patch('datadog.dogstatsd.DogStatsd.increment') + self.statsd_increment_mock = inc_patcher.start() + self.addCleanup(inc_patcher.stop) + + gauge_patcher = mock.patch('datadog.dogstatsd.DogStatsd.gauge') + self.statsd_gauge_mock = gauge_patcher.start() + self.addCleanup(gauge_patcher.stop) def assert_statsd_counter(self, metric, value, tags=None): - """Assert that a statsd counter metric has a certain value. + """Assert that a statsd increment was called for a metric. Parameters: metric: name of the metric - value: expected value of said metric + value: kept for call-site compatibility (not asserted, since + increment() uses a default value internally) tags: tags associated with the metric (dimensions) """ - self.statsd_report_mock.assert_any_call(metric, 'c', value, tags, None) + if tags is not None: + self.statsd_increment_mock.assert_any_call(metric, tags=tags) + else: + self.statsd_increment_mock.assert_any_call(metric) def assert_statsd_gauge(self, metric, value, tags=None): """Assert that a statsd gauge metric has a certain value. @@ -127,7 +135,10 @@ def assert_statsd_gauge(self, metric, value, tags=None): value: expected value of said metric tags: tags associated with the metric (dimensions) """ - self.statsd_report_mock.assert_any_call(metric, 'g', value, tags, None) + if tags is not None: + self.statsd_gauge_mock.assert_any_call(metric, value, tags=tags) + else: + self.statsd_gauge_mock.assert_any_call(metric, value) def create_middleware(self, cb, **kwargs): """Implement abstract method from base class.""" @@ -211,7 +222,8 @@ def build_event_list(self, req, resp=None, middleware_cfg=None, tags=_make_tags(e)) # will not check for operational metrics else: - self.statsd_report_mock.assert_not_called() + self.statsd_increment_mock.assert_not_called() + self.statsd_gauge_mock.assert_not_called() return [e.as_dict() for e in events] diff --git a/test-requirements.txt b/test-requirements.txt index 2a9bc5b..2b23401 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -2,7 +2,7 @@ # of appearance. Changing the order has an impact on the overall integration # process, which may cause wedges in the gate later. -datadog==0.51.0 # 0.31.0 causing test errors +datadog==0.52.1 # 0.31.0 causing test errors hacking>=8.0.0,<8.1.0 # Apache-2.0 # hacking==6.0.1 relies on py3.8 # Apache-2.0 flake8-docstrings~=1.7.0 # MIT