From 418f9dd40a5f38e3c7e3f3fe6727e498aaedc7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20HUBSCHER?= Date: Mon, 14 Oct 2013 13:00:35 +0200 Subject: [PATCH] Add test for columns + badge on README --- README.rst | 11 +++++++++++ chartjs/views/columns.py | 6 +++--- demo/demoproject/tests.py | 8 ++++++++ demo/demoproject/urls.py | 14 ++++++++++++-- demo/demoproject/views.py | 12 ++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index c2b2ab0..fc9f15d 100644 --- a/README.rst +++ b/README.rst @@ -4,6 +4,17 @@ Django Chartjs Django Chartjs lets you manage charts in you Django application. +.. image:: https://secure.travis-ci.org/novapost/django-chartjs.png?branch=master + :alt: Build Status + :target: https://secure.travis-ci.org/novapost/django-chartjs +.. image:: https://coveralls.io/repos/novapost/django-chartjs/badge.png?branch=master + :alt: Coverage Status on master + :target: https://coveralls.io/r/novapost/django-chartjs?branch=master +.. image:: https://pypip.in/v/django-chartjs/badge.png + :target: https://crate.io/packages/django-chartjs/ +.. image:: https://pypip.in/d/django-chartjs/badge.png + :target: https://crate.io/packages/django-chartjs/ + This is compatible with Chart.js and Highcharts JS librairies. Using a set of predefined Class Based Views your are able to get diff --git a/chartjs/views/columns.py b/chartjs/views/columns.py index 219f7e5..f9fad66 100644 --- a/chartjs/views/columns.py +++ b/chartjs/views/columns.py @@ -34,7 +34,7 @@ def get_title(self): """Return graph title.""" try: return {'text': u'%s' % self.title} - except AttributeError: + except AttributeError: # pragma: no cover raise NotImplementedError( # pragma: no cover 'You should define self.title or self.get_title') @@ -63,7 +63,7 @@ def get_yTitle(self): def get_yUnit(self): try: return self.yUnit - except AttributeError: + except AttributeError: # pragma: no cover raise NotImplementedError( # pragma: no cover 'Please define the yAxis unit (self.yUnit).') @@ -120,6 +120,6 @@ def get_providers(self): """ try: return self.providers - except AttributeError: + except AttributeError: # pragma: no cover raise NotImplementedError( # pragma: no cover 'You should define self.providers of self.get_providers.') diff --git a/demo/demoproject/tests.py b/demo/demoproject/tests.py index 0d41475..4ad7b2d 100644 --- a/demo/demoproject/tests.py +++ b/demo/demoproject/tests.py @@ -30,6 +30,14 @@ def test_colorview(self): class HighChartJSTestCase(TestCase): + + def test_column_chartjs_json(self): + resp = self.client.get(reverse('column_highchart_json')) + try: + json.loads(decode(resp.content)) + except ValueError: + self.fail("%r is not valid json" % self.resp.content) + def test_list_chartjs_json(self): resp = self.client.get(reverse('line_highchart_json')) try: diff --git a/demo/demoproject/urls.py b/demo/demoproject/urls.py index d7d6a1f..68901ca 100644 --- a/demo/demoproject/urls.py +++ b/demo/demoproject/urls.py @@ -9,10 +9,20 @@ '', url(r'^$', home, name='home'), url(r'^colors/$', views.colors, name='colors'), - url(r'^line_chart/$', views.line_chart, name='line_chart'), - url(r'^line_chart/json/$', views.line_chart_json, name='line_chart_json'), + + # Column + url(r'^column_highchart/json/$', views.column_highchart_json, + name='column_highchart_json'), + + # Line chart + url(r'^line_chart/$', views.line_chart, + name='line_chart'), + url(r'^line_chart/json/$', views.line_chart_json, + name='line_chart_json'), url(r'^line_highchart/json/$', views.line_highchart_json, name='line_highchart_json'), + + # Pie url(r'^pie_highchart/json/$', views.pie_highchart_json, name='pie_highchart_json'), url(r'^donut_highchart/json/$', views.donut_highchart_json, diff --git a/demo/demoproject/views.py b/demo/demoproject/views.py index be44b75..1880764 100644 --- a/demo/demoproject/views.py +++ b/demo/demoproject/views.py @@ -4,6 +4,7 @@ from django.views.generic import TemplateView from chartjs.colors import next_color, COLORS +from chartjs.views.columns import BaseColumnsHighChartsView from chartjs.views.lines import BaseLineChartView, HighchartPlotLineChartView from chartjs.views.pie import HighChartPieView, HighChartDonutView @@ -38,6 +39,16 @@ def get_colors(self): return next_color(colors) +class ColumnHighChartJSONView(ChartMixin, BaseColumnsHighChartsView): + title = 'Column Highchart test' + yUnit = '%' + providers = ['All'] + credits = False + + def get_data(self): + return [super(ColumnHighChartJSONView, self).get_data()] + + class LineChartJSONView(ChartMixin, BaseLineChartView): pass @@ -57,6 +68,7 @@ class DonutHighChartJSONView(ChartMixin, HighChartDonutView): # Pre-configured views. colors = ColorsView.as_view() +column_highchart_json = ColumnHighChartJSONView.as_view() line_chart = TemplateView.as_view(template_name='line_chart.html') line_chart_json = LineChartJSONView.as_view() line_highchart_json = LineHighChartJSONView.as_view()