From e9c843a4eb817daf249167b79ba3c60237bb93e9 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Wed, 27 Dec 2023 13:10:01 +0100 Subject: Generate graphs when data is updated. --- rrd/tests/test_graphs.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 rrd/tests/test_graphs.py (limited to 'rrd/tests/test_graphs.py') 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()) -- cgit v1.2.3