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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
from chartkick.django import *
import pytest
class TestDjango:
def test_line_chart(self):
self.assert_chart(LineChart([]))
def test_pie_chart(self):
self.assert_chart(PieChart([]))
def test_column_chart(self):
self.assert_chart(ColumnChart([]))
def test_bar_chart(self):
self.assert_chart(BarChart([]))
def test_area_chart(self):
self.assert_chart(AreaChart([]))
def test_scatter_chart(self):
self.assert_chart(ScatterChart([]))
def test_geo_chart(self):
self.assert_chart(GeoChart([]))
def test_timeline(self):
self.assert_chart(Timeline([]))
def test_escape_data(self):
chart = LineChart('</script><script>alert("xss")</script>')
assert '\\u003Cscript\\u003E' in str(chart)
assert '<script>alert' not in str(chart)
def test_escape_options(self):
chart = LineChart([], xss='</script><script>alert("xss")</script>')
assert '\\u003Cscript\\u003E' in str(chart)
assert '<script>alert' not in str(chart)
def test_height_pixels(self):
assert 'height: 100px;' in str(LineChart([], height='100px'))
def test_height_percent(self):
assert 'height: 100%;' in str(LineChart([], height='100%'))
def test_height_dot(self):
assert 'height: 2.5rem;' in str(LineChart([], height='2.5rem'))
def test_height_quote(self):
with pytest.raises(ValueError) as excinfo:
LineChart([], height='150px"')
assert 'Invalid height' in str(excinfo.value)
def test_height_semicolon(self):
with pytest.raises(ValueError) as excinfo:
LineChart([], height='150px;background:123')
assert 'Invalid height' in str(excinfo.value)
def test_width_pixels(self):
assert 'width: 100px;' in str(LineChart([], width='100px'))
def test_width_percent(self):
assert 'width: 100%;' in str(LineChart([], width='100%'))
def test_width_dot(self):
assert 'width: 2.5rem;' in str(LineChart([], width='2.5rem'))
def test_width_quote(self):
with pytest.raises(ValueError) as excinfo:
LineChart([], width='80%"')
assert 'Invalid width' in str(excinfo.value)
def test_width_semicolon(self):
with pytest.raises(ValueError) as excinfo:
LineChart([], width='80%;background:123')
assert 'Invalid width' in str(excinfo.value)
def test_loading(self):
assert '>Loading!!</div>' in str(LineChart([], loading='Loading!!'))
def test_loading_escaped(self):
assert '<b>Loading!!</b>' in str(LineChart([], loading='<b>Loading!!</b>'))
assert '<b>' not in str(LineChart([], loading='<b>Loading!!</b>'))
def assert_chart(self, chart):
assert 'new Chartkick' in str(chart)
|