diff --git a/components/notifier/ci/unittest.sh b/components/notifier/ci/unittest.sh new file mode 100755 index 0000000000..785be62e8b --- /dev/null +++ b/components/notifier/ci/unittest.sh @@ -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 diff --git a/components/notifier/requirements-dev.txt b/components/notifier/requirements-dev.txt index 11c4a042f9..2217ec1ae9 100644 --- a/components/notifier/requirements-dev.txt +++ b/components/notifier/requirements-dev.txt @@ -1 +1,2 @@ +coverage==5.3 pip==20.2.3 diff --git a/components/notifier/src/strategies/reds_per_report.py b/components/notifier/src/strategies/reds_per_report.py index 634645771a..08870bdcfa 100644 --- a/components/notifier/src/strategies/reds_per_report.py +++ b/components/notifier/src/strategies/reds_per_report.py @@ -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 diff --git a/components/notifier/tests/strategies/__init__.py b/components/notifier/tests/strategies/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/components/notifier/tests/strategies/test_reds_per_report.py b/components/notifier/tests/strategies/test_reds_per_report.py new file mode 100644 index 0000000000..09e0f41872 --- /dev/null +++ b/components/notifier/tests/strategies/test_reds_per_report.py @@ -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))