aboutsummaryrefslogtreecommitdiff
path: root/rrd/tests/test_graphs.py
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2023-12-27 13:10:01 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2023-12-29 07:29:22 +0100
commite9c843a4eb817daf249167b79ba3c60237bb93e9 (patch)
treeea60527374dc05f333dd6122fc1517e68558b8bf /rrd/tests/test_graphs.py
parent27bc8de7c7f8e29ba10324b56fef9fc4e80a9fd6 (diff)
Generate graphs when data is updated.
Diffstat (limited to 'rrd/tests/test_graphs.py')
-rw-r--r--rrd/tests/test_graphs.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/rrd/tests/test_graphs.py b/rrd/tests/test_graphs.py
new file mode 100644
index 0000000..f2a4948
--- /dev/null
+++ b/rrd/tests/test_graphs.py
@@ -0,0 +1,39 @@
+import datetime
+import os
+
+from django.conf import settings
+from django.test import TestCase
+
+from .. import models
+
+
+class TestGraphs(TestCase):
+ def setUp(self):
+ self.rrd_file = "test.rrd"
+ try:
+ os.remove(os.path.join(settings.RRD_DB_PATH, self.rrd_file))
+ except FileNotFoundError:
+ pass
+
+ def tearDown(self):
+ try:
+ os.remove(os.path.join(settings.RRD_DB_PATH, self.rrd_file))
+ except FileNotFoundError:
+ pass
+
+ def test_generate_at_ds_update(self):
+ ds = models.DataSource.objects.create(
+ topic="test",
+ path=self.rrd_file,
+ )
+ graph = models.Graph.objects.create(
+ title="Test Graph",
+ path="test/test.png",
+ )
+ graph.data_sources.add(ds)
+ graph.save()
+ now = datetime.datetime.now()
+ ts = int(now.timestamp())
+ ds.update(ts, 10)
+ stat = os.stat(os.path.join(settings.RRD_GRAPH_PATH, "test/test.png"))
+ self.assertGreaterEqual(stat.st_mtime, now.timestamp())