Skip to content

Commit

Permalink
Add unit tests for the strategies module. (#1541)
Browse files Browse the repository at this point in the history
* Add unit tests for the strategies module.
  • Loading branch information
fniessink authored Oct 8, 2020
1 parent f3a0d6f commit f90de2c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
14 changes: 14 additions & 0 deletions components/notifier/ci/unittest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# We currently get one warning when running Python in dev mode:
# aiohttp/helpers.py:107: DeprecationWarning: "@coroutine" decorator is deprecated since Python 3.8, use "async def" instead
# Turn off dev mode until aiohttp gets fixed or there's a way to suppress warnings in third party code
# export PYTHONDEVMODE=1

# For Windows compatibility; prevent path from ending with a ':'
export PYTHONPATH=`python -c 'import sys;print(":".join(sys.argv[1:]))' src $PYTHONPATH`
export COVERAGE_RCFILE=../../.coveragerc
coverage run -m unittest --quiet
coverage xml
coverage html
coverage report
1 change: 1 addition & 0 deletions components/notifier/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
coverage==5.3
pip==20.2.3
2 changes: 0 additions & 2 deletions components/notifier/src/strategies/reds_per_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ def reds_per_report(json) -> List:
red_metrics = []
for report in json["reports"]:
red_metrics.append([report["report_uuid"], 0])
print(report["report_uuid"])
for subject in report["subjects"].values():
for metric in subject["metrics"].values():
print(metric["status"], flush=True)
if metric["status"] == "target_not_met":
red_metrics[-1][1] += 1
return red_metrics
Empty file.
29 changes: 29 additions & 0 deletions components/notifier/tests/strategies/test_reds_per_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Unit tests for the notification strategies."""

import unittest

from strategies.reds_per_report import reds_per_report


class RedsPerReportTestCase(unittest.TestCase):
"""Unit tests for the reds per report notification strategy."""

def test_no_reports(self):
"""Test that there is nothing to notify when there are no reports."""
self.assertEqual([], reds_per_report(dict(reports=[])))

def test_no_red_metrics(self):
"""Test that there is nothing to notify when there are no red metrics."""
green_metric = dict(status="target_met")
subject1 = dict(metrics=dict(metric1=green_metric))
report1 = dict(report_uuid="report1", subjects=dict(subject1=subject1))
json = dict(reports=[report1])
self.assertEqual([["report1", 0]], reds_per_report(json))

def test_red_metrics(self):
"""Test that the number of red metrics is returned."""
red_metric = dict(status="target_not_met")
subject1 = dict(metrics=dict(metric1=red_metric))
report1 = dict(report_uuid="report1", subjects=dict(subject1=subject1))
json = dict(reports=[report1])
self.assertEqual([["report1", 1]], reds_per_report(json))

0 comments on commit f90de2c

Please sign in to comment.