removed grafana and victoria
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import sys
|
||||
import tempfile
|
||||
import types
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class FakeRRD(types.ModuleType):
|
||||
def __init__(self):
|
||||
super().__init__("rrdtool")
|
||||
self.created = []
|
||||
self.updated = []
|
||||
self.graphed = []
|
||||
|
||||
def create(self, *args):
|
||||
self.created.append(args)
|
||||
Path(args[0]).touch()
|
||||
|
||||
def update(self, *args):
|
||||
self.updated.append(args)
|
||||
|
||||
def graph(self, *args):
|
||||
self.graphed.append(args)
|
||||
Path(args[0]).write_bytes(b"png")
|
||||
|
||||
|
||||
fake_rrd = FakeRRD()
|
||||
sys.modules.setdefault("rrdtool", fake_rrd)
|
||||
|
||||
from hue_collector.rrd_store import RRDStore # noqa: E402
|
||||
|
||||
|
||||
class RRDStoreTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
fake_rrd.created.clear()
|
||||
fake_rrd.updated.clear()
|
||||
fake_rrd.graphed.clear()
|
||||
self.tempdir = tempfile.TemporaryDirectory()
|
||||
self.store = RRDStore(self.tempdir.name, 30)
|
||||
|
||||
def tearDown(self):
|
||||
self.tempdir.cleanup()
|
||||
|
||||
def test_create_update_and_group_graph(self):
|
||||
group = {"id": "r-1", "type": "room", "available": 2, "on": 1, "off": 1, "unavailable": 1, "brightness": 42.5}
|
||||
self.store.update({"groups": [group], "sensors": []})
|
||||
self.assertEqual(len(fake_rrd.created), 1)
|
||||
self.assertTrue(fake_rrd.updated[0][1].endswith(":2:1:1:1:42.5"))
|
||||
self.assertEqual(self.store.graph("group", group, "24h"), b"png")
|
||||
graph_args = fake_rrd.graphed[0]
|
||||
self.assertIn("AREA:up#8b0000:Unavailable", graph_args)
|
||||
self.assertIn("LINE2:b#22c55e:Average intensity", graph_args)
|
||||
|
||||
def test_rejects_unsafe_identifier(self):
|
||||
with self.assertRaises(ValueError):
|
||||
self.store.path("group", "../escape")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user