Skip to content

Commit

Permalink
Add test for columns + badge on README
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémy HUBSCHER committed Oct 14, 2013
1 parent e5811fc commit 418f9dd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
11 changes: 11 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions chartjs/views/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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).')

Expand Down Expand Up @@ -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.')
8 changes: 8 additions & 0 deletions demo/demoproject/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 12 additions & 2 deletions demo/demoproject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions demo/demoproject/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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()
Expand Down

0 comments on commit 418f9dd

Please sign in to comment.