def test_has_subtotals(self): r = SimpleDemoReport.as_report() self.assertFalse(r.has_subtotals()) r.column_totals = ['integer1'] self.assertTrue(r.has_subtotals())
def test_render_to_response(self): report = SimpleDemoReport.as_report() renderer = report.get_renderer_for_format('html') self.assertIsInstance(renderer, BaseHtmlRender) request = get_fake_request() r = renderer.render_to_response(request) self.assertIsInstance(r, HttpResponse)
def test_render_to_response(self): G(SimpleDemoModel, n=2, char='abc', integer1=1, integer2=2, boolean=True) G(SimpleDemoModel, n=2, char=u'êbc', integer1=1, integer2=2, boolean=True) report = SimpleDemoReport.as_report() renderer = report.get_renderer_for_format('xls') self.assertIsInstance(renderer, BaseXlsRender) request = get_fake_request() r = renderer.render_to_response(request) self.assertIsInstance(r, HttpResponse)
def test_report_groupby(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class, ), groupby=[ ('date', 'Date'), ])() self.assertIn('_report_group_by', form.base_fields) self.assertIsInstance(form.base_fields['_report_group_by'], forms.ChoiceField)
def test_get_groups(self): r = SimpleDemoReport.as_report() with self.assertRaises(ImproperlyConfigured): r.get_groups() G(SimpleDateModel, char='abc', date=datetime.date.today(), date_range=datetime.date.today()) r = SimpleDateReport.as_report(datasource=SimpleDateModelSource.as_datasource()) g = r.get_groups() self.assertEqual(len(g), 1)
def test_get_filters(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class, ), filtering=['integer1'])() form.cleaned_data = {'integer1': 1, 'char': ['a', 'b', 'c']} f = form.get_filters() self.assertSequenceEqual(([], {'integer1': 1}), f) form.cleaned_data = {'integer1': [1, 2, 3]} f = form.get_filters() self.assertSequenceEqual(([], {'integer1__in': [1, 2, 3]}), f)
def test_get_filters_summary(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class, ))() form.cleaned_data = { 'integer1': 1, } self.assertEqual(form.get_filters_summary(), {u'Integer #1': 1}) form.cleaned_data = {'integer1': [1, 2, 3]} form.get_filters() self.assertEqual(form.get_filters_summary(), {u'Integer #1': [1, 2, 3]})
def test_get_filters_summary(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class,))() form.cleaned_data = { 'integer1': 1, } self.assertEqual(form.get_filters_summary(), {u'Integer #1': 1}) form.cleaned_data = { 'integer1': [1, 2, 3] } form.get_filters() self.assertEqual(form.get_filters_summary(), {u'Integer #1': [1, 2, 3]})
def test_get_groups(self): r = SimpleDemoReport.as_report() with self.assertRaises(ImproperlyConfigured): r.get_groups() G(SimpleDateModel, char='abc', date=datetime.date.today(), date_range=datetime.date.today()) r = SimpleDateReport.as_report( datasource=SimpleDateModelSource.as_datasource()) g = r.get_groups() self.assertEqual(len(g), 1)
def test_get_filters(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class,), filtering=['integer1'])() form.cleaned_data = { 'integer1': 1, 'char': ['a', 'b', 'c'] } f = form.get_filters() self.assertSequenceEqual(([], {'integer1': 1}), f) form.cleaned_data = { 'integer1': [1, 2, 3] } f = form.get_filters() self.assertSequenceEqual(([], {'integer1__in': [1, 2, 3]}), f)
def test_clean__report_group_by(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class, ), groupby=[ ('date', 'Date'), ])() form.cleaned_data = {'date': '2001-01-01', '_report_group_by': 'date'} self.assertIsNone(form.clean__report_group_by()) form.cleaned_data = { 'date': '2001-01-01', '_report_group_by': 'date,internal' } group, internal_order = form.clean__report_group_by() self.assertEqual(group, 'date') self.assertEqual(internal_order, 'internal')
def test_clean__report_group_by(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class,), groupby=[('date', 'Date'), ])() form.cleaned_data = { 'date': '2001-01-01', '_report_group_by': 'date' } self.assertIsNone(form.clean__report_group_by()) form.cleaned_data = { 'date': '2001-01-01', '_report_group_by': 'date,internal' } group, internal_order = form.clean__report_group_by() self.assertEqual(group, 'date') self.assertEqual(internal_order, 'internal')
def test_format_labels(self): r = SimpleDemoReport.as_report() self.assertSequenceEqual(sorted(r.get_format_labels()), ['html', 'xls'])
def test_get_renderer_class_format(self): r = SimpleDemoReport.as_report() self.assertEqual(r.get_renderer_class_for_format('html'), BaseHtmlRender)
def test_items_other(self): G(SimpleDemoModel, char='abc') r = SimpleDemoReport.as_report() r.list_display = ['char', 'integer1'] g = BaseGrouper(r, 'wrong', 'wrong') self.assertEqual(list(g.items()), [(None, list(r))])
def test_get_format_labels(self): r = SimpleDemoReport.as_report() self.assertEqual(r.formats_dict, {'html': BaseHtmlRender, 'xls': BaseXlsRender})
def test_report_groupby(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class,), groupby=[('date', 'Date'), ])() self.assertIn('_report_group_by', form.base_fields) self.assertIsInstance(form.base_fields['_report_group_by'], forms.ChoiceField)
def test_init(self): r = SimpleDemoReport.as_report() c = reportform_factory(r) self.assertIn('_format', c.base_fields)
def test_get_format_labels(self): r = SimpleDemoReport.as_report() self.assertEqual(r.formats_dict, { 'html': BaseHtmlRender, 'xls': BaseXlsRender })
def test_get_config_form_class(self): r = SimpleDemoReport.as_report() f = reportform_factory(r, bases=(r.config_form_class, )) self.assertIn('integer1', f.base_fields) self.assertIn('_format', f.base_fields)
def test_format_labels(self): r = SimpleDemoReport.as_report() self.assertEqual(r.get_format_labels(), ['html', 'xls'])
def test_get_renderer_for_format(self): r = SimpleDemoReport.as_report() renderer = r.get_renderer_for_format('html') self.assertIsInstance(renderer, BaseHtmlRender)
def test_get_lookup_fields(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class, ), filtering=['integer1'])() f = form.get_lookup_fields() self.assertEqual(['integer1'], f)
def test_get_lookup_fields(self): r = SimpleDemoReport.as_report() form = reportform_factory(r, (r.config_form_class,), filtering=['integer1'])() f = form.get_lookup_fields() self.assertEqual(['integer1'], f)
def test_repr(self): r = SimpleDemoReport.as_report() self.assertEqual(repr(r), "<SimpleDemoReport: on `SimpleDemoModel`>")
def test_datasource_custom_list_display(self): G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20) r = SimpleDemoReport.as_report() self.assertEqual(r.datasource[1].values(), [u'abc', 10]) self.assertEqual(r[1], (u'abc',)) self.assertSequenceEqual(r[:1], [(u'abc',)])
def test_get_config_form_class(self): r = SimpleDemoReport.as_report() f = reportform_factory(r, bases=(r.config_form_class,)) self.assertIn('integer1', f.base_fields) self.assertIn('_format', f.base_fields)
def test_datasource_custom_list_display(self): G(SimpleDemoModel, n=2, char='abc', integer1=10, integer2=20) r = SimpleDemoReport.as_report() self.assertEqual(r.datasource[1].values(), [u'abc', 10]) self.assertEqual(r[1], (u'abc', )) self.assertSequenceEqual(r[:1], [(u'abc', )])