Skip to content

Commit

Permalink
Merge pull request #2 from lsst-it/IT-5270/severity-ok
Browse files Browse the repository at this point in the history
fix sanitize_severity() maping "ok" -> "Ok" (not all caps)
  • Loading branch information
jhoblitt committed May 6, 2024
2 parents f2e4358 + 2f26684 commit ae82842
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ jobs:
- name: flake8 Lint
uses: py-actions/flake8@v2

pytest:
runs-on: ubuntu-latest
steps:
- name: Check out source repository
uses: actions/checkout@v4
- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install .
- name: pytest
run: pytest

hadolint:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion gnocpush/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')

Expand Down
8 changes: 8 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies = [
"flask",
"globalnoc_alertmon_agent",
"prometheus-flask-exporter==0.23.0",
"pytest",
"python-dateutil",
"requests",
"waitress",
Expand All @@ -24,3 +25,10 @@ ignore = ['E221', 'E251']

[tool.setuptools.packages.find]
exclude = ["charts"]

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-q"
testpaths = [
"tests",
]
33 changes: 33 additions & 0 deletions tests/test_severity.py
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit ae82842

Please sign in to comment.