57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
import pytest
|
|
|
|
from dashboard import Widget
|
|
|
|
def test_healthscore_1_asc():
|
|
w = Widget(
|
|
{
|
|
"type": "gauge",
|
|
"stops": [1, 5],
|
|
"data": [ "605da6f41f58b122f41283823a99faa36286961a106ac901bb2b2d730fddc778" ] # required by API, not used for tests
|
|
}
|
|
)
|
|
# stops are ordered from best to worst
|
|
assert w.healthscore(0) == 100
|
|
assert w.healthscore(1) == 100
|
|
assert w.healthscore(2) == 75
|
|
assert w.healthscore(3) == 50
|
|
assert w.healthscore(4) == 25
|
|
assert w.healthscore(5) == 0
|
|
assert w.healthscore(6) == 0
|
|
|
|
|
|
def test_healthscore_2_asc():
|
|
w = Widget(
|
|
{
|
|
"type": "gauge",
|
|
"stops": [1, 10, 100],
|
|
"data": [ "605da6f41f58b122f41283823a99faa36286961a106ac901bb2b2d730fddc778" ] # required by API, not used for tests
|
|
}
|
|
)
|
|
# stops are ordered from best to worst
|
|
assert w.healthscore(0) == 100
|
|
assert w.healthscore(1) == 100
|
|
assert w.healthscore(5.5) == 75
|
|
assert w.healthscore(10) == 50
|
|
assert w.healthscore(55) == 25
|
|
assert w.healthscore(100) == 0
|
|
assert w.healthscore(1000) == 0
|
|
|
|
def test_healthscore_2_desc():
|
|
w = Widget(
|
|
{
|
|
"type": "gauge",
|
|
"stops": [100, 10, 1],
|
|
"data": [ "605da6f41f58b122f41283823a99faa36286961a106ac901bb2b2d730fddc778" ] # required by API, not used for tests
|
|
}
|
|
)
|
|
# stops are ordered from best to worst
|
|
assert w.healthscore(0) == 0
|
|
assert w.healthscore(1) == 0
|
|
assert w.healthscore(5.5) == 25
|
|
assert w.healthscore(10) == 50
|
|
assert w.healthscore(55) == 75
|
|
assert w.healthscore(100) == 100
|
|
assert w.healthscore(1000) == 100
|
|
|