Skip to content
Snippets Groups Projects
Commit e7ea21f3 authored by Alice Heaton's avatar Alice Heaton :speech_balloon:
Browse files

Fix tests after renaming of widget, and add new tests for the term count chart widget.

parent 23e911ba
No related branches found
No related tags found
No related merge requests found
from django.test import TestCase
from hid.widgets.chart import QuestionChartWidget
class TestQuestionChartWidget(TestCase):
def test_context_data_includes_widget_name(self):
widget = QuestionChartWidget()
context_data = widget.get_context_data(name='test-name', questions={})
self.assertEqual(context_data['name'], 'test-name')
def test_context_data_includes_flot_options(self):
widget = QuestionChartWidget()
context_data = widget.get_context_data(name='test-name', questions={})
self.assertTrue('options' in context_data)
def test_context_data_includes_flot_data(self):
widget = QuestionChartWidget()
context_data = widget.get_context_data(name='test-name', questions={})
self.assertTrue('data' in context_data)
def test_context_data_includes_correct_data(self):
widget = QuestionChartWidget()
context_data = widget.get_context_data(name='test-name', questions={
'question one': 345,
'question two': 782
})
self.assertEqual(
context_data['data'],
[[[345, 0], [782, 1]]]
)
def test_chart_questions_are_set_as_yaxis_value_labels(self):
widget = QuestionChartWidget()
context_data = widget.get_context_data(name='test-name', questions={
'question one': 345,
'question two': 782
})
self.assertEqual(
context_data['options']['yaxis']['ticks'],
[[0, 'question one'], [1, 'question two']]
)
from mock import patch
from django.test import TestCase
from hid.widgets.term_count_chart import TermCountChartWidget
class TestTermCountChartWidget(TestCase):
def test_context_data_includes_widget_title(self):
widget = TermCountChartWidget()
with patch('hid.widgets.term_count_chart.term_itemcount') as itemcount:
itemcount.return_value = []
context_data = widget.get_context_data(
title='test-name', taxonomy='tax'
)
self.assertEqual(context_data['title'], 'test-name')
def test_context_data_includes_flot_options(self):
widget = TermCountChartWidget()
with patch('hid.widgets.term_count_chart.term_itemcount') as itemcount:
itemcount.return_value = []
context_data = widget.get_context_data(
title='test-name', taxonomy='tax'
)
self.assertTrue('options' in context_data)
def test_context_data_includes_flot_data(self):
widget = TermCountChartWidget()
with patch('hid.widgets.term_count_chart.term_itemcount') as itemcount:
itemcount.return_value = []
context_data = widget.get_context_data(
title='test-name', taxonomy='tax'
)
self.assertTrue('data' in context_data)
def test_context_data_includes_correct_data(self):
widget = TermCountChartWidget()
with patch('hid.widgets.term_count_chart.term_itemcount') as itemcount:
itemcount.return_value = [
{
'name': 'name one',
'long_name': 'long name one',
'count': 345
},
{
'name': 'name two',
'long_name': 'long name two',
'count': 782
},
]
context_data = widget.get_context_data(
title='test-name', taxonomy='tax'
)
self.assertEqual(
context_data['data'],
[[[345, 2], [782, 1]]]
)
def test_chart_questions_are_set_as_yaxis_value_labels(self):
widget = TermCountChartWidget()
with patch('hid.widgets.term_count_chart.term_itemcount') as itemcount:
itemcount.return_value = [
{
'name': 'name one',
'long_name': 'long name one',
'count': 345
},
{
'name': 'name two',
'long_name': 'long name two',
'count': 782
},
]
context_data = widget.get_context_data(
title='test-name', taxonomy='tax'
)
self.assertEqual(
context_data['options']['yaxis']['ticks'],
[[2, 'long name one'], [1, 'long name two']]
)
def test_fetch_counts_orders_by_long_name(self):
widget = TermCountChartWidget()
with patch('hid.widgets.term_count_chart.term_itemcount') as itemcount:
itemcount.return_value = [
{
'name': 'aaa-name',
'long_name': 'zzz-long-name',
'count': 0
},
{
'name': 'zzz-name',
'long_name': 'aaa-long-name',
'count': 1000
},
]
counts = widget._fetch_counts('tax', 0, 'Others')
self.assertEqual(
counts.items(),
[('aaa-long-name', 1000), ('zzz-long-name', 0)]
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment