diff --git a/django/website/hid/tests/term_count_widget_tests.py b/django/website/hid/tests/term_count_widget_tests.py index 92084fd9e3c248f0e6ca86324e8292b85b8705c9..6d8e2ddec5a1fea598f9ba653a4866d6da735393 100644 --- a/django/website/hid/tests/term_count_widget_tests.py +++ b/django/website/hid/tests/term_count_widget_tests.py @@ -99,3 +99,40 @@ class TestTermCountChartWidget(TestCase): counts.items(), [('aaa-long-name', 1000), ('zzz-long-name', 0)] ) + + def test_fetch_counts_gets_n_larger_and_aggregates_others_items(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': 1 + }, + { + 'name': 'name two', + 'long_name': 'long-name two', + 'count': 10 + }, + { + 'name': 'name three', + 'long_name': 'long-name three', + 'count': 20 + }, + { + 'name': 'name four', + 'long_name': 'long-name four', + 'count': 30 + }, + + ] + counts = widget._fetch_counts('tax', 3, 'Others') + + self.assertEqual( + counts.items(), + [ + ('long-name four', 30), ('long-name three', 20), + ('Others', 11) + ] + )