Debian Codegraph @

tests/test_django.py

raw symbols SCIP
1 from chartkick.django import LineChart, PieChart, ColumnChart, BarChart, AreaChart, ScatterChart, GeoChart, Timeline
2 import pytest
3
4
5 class TestDjango:
6 def test_line_chart(self):
7 self.assert_chart(LineChart([]))
8
9 def test_pie_chart(self):
10 self.assert_chart(PieChart([]))
11
12 def test_column_chart(self):
13 self.assert_chart(ColumnChart([]))
14
15 def test_bar_chart(self):
16 self.assert_chart(BarChart([]))
17
18 def test_area_chart(self):
19 self.assert_chart(AreaChart([]))
20
21 def test_scatter_chart(self):
22 self.assert_chart(ScatterChart([]))
23
24 def test_geo_chart(self):
25 self.assert_chart(GeoChart([]))
26
27 def test_timeline(self):
28 self.assert_chart(Timeline([]))
29
30 def test_escape_data(self):
31 chart = LineChart('</script><script>alert("xss")</script>')
32 assert '\\u003Cscript\\u003E' in str(chart)
33 assert '<script>alert' not in str(chart)
34
35 def test_escape_options(self):
36 chart = LineChart([], xss='</script><script>alert("xss")</script>')
37 assert '\\u003Cscript\\u003E' in str(chart)
38 assert '<script>alert' not in str(chart)
39
40 def test_height_pixels(self):
41 assert 'height: 100px;' in str(LineChart([], height='100px'))
42
43 def test_height_percent(self):
44 assert 'height: 100%;' in str(LineChart([], height='100%'))
45
46 def test_height_dot(self):
47 assert 'height: 2.5rem;' in str(LineChart([], height='2.5rem'))
48
49 def test_height_quote(self):
50 with pytest.raises(ValueError) as excinfo:
51 LineChart([], height='150px"')
52 assert 'Invalid height' in str(excinfo.value)
53
54 def test_height_semicolon(self):
55 with pytest.raises(ValueError) as excinfo:
56 LineChart([], height='150px;background:123')
57 assert 'Invalid height' in str(excinfo.value)
58
59 def test_width_pixels(self):
60 assert 'width: 100px;' in str(LineChart([], width='100px'))
61
62 def test_width_percent(self):
63 assert 'width: 100%;' in str(LineChart([], width='100%'))
64
65 def test_width_dot(self):
66 assert 'width: 2.5rem;' in str(LineChart([], width='2.5rem'))
67
68 def test_width_quote(self):
69 with pytest.raises(ValueError) as excinfo:
70 LineChart([], width='80%"')
71 assert 'Invalid width' in str(excinfo.value)
72
73 def test_width_semicolon(self):
74 with pytest.raises(ValueError) as excinfo:
75 LineChart([], width='80%;background:123')
76 assert 'Invalid width' in str(excinfo.value)
77
78 def test_loading(self):
79 assert '>Loading!!</div>' in str(LineChart([], loading='Loading!!'))
80
81 def test_loading_escaped(self):
82 assert '&lt;b&gt;Loading!!&lt;/b&gt;' in str(LineChart([], loading='<b>Loading!!</b>'))
83 assert '<b>' not in str(LineChart([], loading='<b>Loading!!</b>'))
84
85 def assert_chart(self, chart):
86 assert 'new Chartkick' in str(chart)