Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions auditmiddleware/tests/unit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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."""
Expand Down Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down