diff --git a/gnocpush/utils.py b/gnocpush/utils.py index 01ed59c..fb89cf8 100644 --- a/gnocpush/utils.py +++ b/gnocpush/utils.py @@ -15,7 +15,7 @@ def sanitize_severity(severity): case 'major' | 'warning': s = 'Major' case 'minor' | 'info': s = 'Minor' case 'unknown': s = 'Unknown' - case 'ok': s = 'Ok' + case 'ok': s = 'OK' log.debug(f'severity: {severity} -> {s}') diff --git a/pyproject.toml b/pyproject.toml index 801b764..00d182a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ dependencies = [ "flask", "globalnoc_alertmon_agent", "prometheus-flask-exporter==0.23.0", + "pytest", "python-dateutil", "requests", "waitress", @@ -24,3 +25,10 @@ ignore = ['E221', 'E251'] [tool.setuptools.packages.find] exclude = ["charts"] + +[tool.pytest.ini_options] +minversion = "6.0" +addopts = "-q" +testpaths = [ + "tests", +] diff --git a/tests/test_severity.py b/tests/test_severity.py new file mode 100644 index 0000000..5e39035 --- /dev/null +++ b/tests/test_severity.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +from gnocpush.utils import sanitize_severity + + +def test_critical(): + words = ["critical", "CRITICAL", "cRiTiCaL", "Critical"] + for word in words: + assert sanitize_severity(word) == 'Critical' + + +def test_major(): + words = ["major", "MAJOR", "mAjOr", "Major"] + for word in words: + assert sanitize_severity(word) == 'Major' + + +def test_minor(): + words = ["minor", "MINOR", "mInOr", "Minor"] + for word in words: + assert sanitize_severity(word) == 'Minor' + + +def test_unknown(): + words = ["unknown", "UNKNOWN", "uNkNoWn", "Unknown", "foo", "bar", "baz"] + for word in words: + assert sanitize_severity(word) == 'Unknown' + + +def test_ok(): + words = ["ok", "OK", "oK", "Ok"] + for word in words: + assert sanitize_severity(word) == 'OK'