def test_preload_record_data_calls_view(self): obj1 = ExampleModel.objects.create(name='test name 1') queryset = ExampleModel.objects.all() class Dummy(object): def preload_record_data(self, obj): raise Exception('We did it') dt = Datatable(queryset, '/', callback_target=Dummy()) with self.assertRaises(Exception) as cm: dt.get_records() self.assertEqual(str(cm.exception), 'We did it')
def test_get_records_populates_cache(self): ExampleModel.objects.create(name='test name') queryset = ExampleModel.objects.all() dt = Datatable(queryset, '/') dt.get_records() self.assertIsNotNone(dt._records) records = dt._records # _records doesn't change when run again dt.get_records() self.assertEqual(dt._records, records)