1. Mikhail Korobov
  2. django-chart-tools

Commits

Mikhail Korobov  committed bab7952

Tests

  • Participants
  • Parent commits be9c0ce
  • Branches default

Comments (0)

Files changed (2)

File chart_tools/tests.py

View file
  • Ignore whitespace
+#coding: utf-8
+from unittest import TestCase
+from django.template import Template, Context
+from chart_tools.templatetags.chart_tags import prepare_chart
+
+CHART = "<img src='http://chart.apis.google.com/chart?chxr=0,0,160&chxt=y&chbh=a&chs=440x220&cht=bvs&chco=4D89F9&chds=0,160&chd=t:10,50,60,80,40,60,30&chtt=Horizontal+bar+chart' width='440' height='220' alt=''  />"
+
+FIXTURES = {
+'copy_paste': '''
+http://chart.apis.google.com/chart
+   ?chxr=0,0,160
+   &chxt=y
+   &chbh=a
+   &chs=440x220
+   &cht=bvs
+   &chco=4D89F9
+   &chds=0,160
+   &chd=t:10,50,60,80,40,60,30
+   &chtt=Horizontal+bar+chart
+''',
+
+'copy_paste_without_url': '''
+   ?chxr=0,0,160
+   &chxt=y
+   &chbh=a
+   &chs=440x220
+   &cht=bvs
+   &chco=4D89F9
+   &chds=0,160
+   &chd=t:10,50,60,80,40,60,30
+   &chtt=Horizontal+bar+chart
+''',
+
+'formatted': '''
+http://chart.apis.google.com/chart?
+   chxr=0,0,160&
+   chxt=y&
+   chbh=a&
+   chs=440x220&
+   cht=bvs&
+   chco=4D89F9&
+   chds=0,160&
+   chd=t:10,50,60,80,40,60,30&
+   chtt=Horizontal+bar+chart
+''',
+
+'cleaned_up': '''
+   chxr=0,0,160
+   chxt=y
+   chbh=a
+   chs=440x220
+   cht=bvs
+   chco=4D89F9
+   chds=0,160
+   chd=t:10,50,60,80,40,60,30
+   chtt=Horizontal+bar+chart
+'''
+
+}
+
+class PrepareTest(TestCase):
+
+    def assertCorrectChart(self, variant):
+        self.assertEqual(prepare_chart(FIXTURES[variant]), CHART)
+
+    def test_copy_paste(self):
+        self.assertCorrectChart('copy_paste')
+
+    def test_copy_paste2(self):
+        self.assertCorrectChart('copy_paste_without_url')
+
+    def test_formatted(self):
+        self.assertCorrectChart('formatted')
+
+    def test_cleaned_chart(self):
+        self.assertCorrectChart('cleaned_up')
+
+
+class RenderTest(TestCase):
+
+    def assertChartRendered(self, variant):
+        template = '{% load chart_tags %}{% chart %}'+FIXTURES[variant]+'{% endchart %}'
+        rendered = Template(template).render(Context())
+        assert rendered == CHART, "\n%s \n  VV \n%s \n != \n%s" % (template, rendered, CHART)
+
+    def test_copy_paste(self):
+        self.assertChartRendered('copy_paste')
+
+    def test_copy_paste2(self):
+        self.assertChartRendered('copy_paste_without_url')
+
+    def test_formatted(self):
+        self.assertChartRendered('formatted')
+
+    def test_cleaned_chart(self):
+        self.assertChartRendered('cleaned_up')

File runtests.py

View file
  • Ignore whitespace
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from django.conf import settings
+from django.core.management import call_command
+
+settings.configure(
+    INSTALLED_APPS=('chart_tools',),
+    DATABASE_ENGINE = 'sqlite3',
+)
+
+if __name__ == "__main__":
+    call_command('test', 'chart_tools')