blob: 7a4dd135f99103f021ba7e1a315ade3db7ea3e00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
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())
def test_invalid_path(self):
graph = models.Graph.objects.create(
title="Test Graph",
path="../../../etc/evil.png",
)
self.assertTrue(graph.graph_path.endswith("_.._.._.._etc_evil.png"))
self.assertIn(settings.RRD_GRAPH_PATH.as_posix(), graph.graph_path)
|