def test_get_ordering_splits(self):
        # Verify empty has blank db-backed list and virtual list
        dt = Datatable([], '/')
        dt.configure()
        self.assertEqual(dt.get_ordering_splits(), ([], []))

        class DT(Datatable):
            fake = TextColumn('Fake', sources=['get_absolute_url'])

            class Meta:
                model = ExampleModel
                columns = ['name', 'fake']

        # Verify a fake field name ends up separated from the db-backed field
        dt = DT([],
                '/',
                query_config={
                    'order[0][column]': '0',
                    'order[0][dir]': 'asc'
                })  # iSortingCols': '1',
        dt.configure()
        self.assertEqual(dt.get_ordering_splits(), (['name'], []))

        # Verify ['name', 'fake'] ordering sends 'name' to db sort list, but keeps 'fake' in manual
        # sort list.
        dt = DT(
            [],
            '/',
            query_config={
                'order[0][column]': '0',
                'order[0][dir]': 'asc',
                'order[1][column]': '1',
                'order[1][dir]': 'asc'
            })  # 'iSortingCols': '2',
        dt.configure()
        self.assertEqual(dt.get_ordering_splits(), (['name'], ['fake']))

        # Verify a fake field name as the sort column correctly finds no db sort fields
        dt = DT([],
                '/',
                query_config={
                    'order[0][column]': '1',
                    'order[0][dir]': 'asc'
                })  # 'iSortingCols': '1',
        dt.configure()
        self.assertEqual(dt.get_ordering_splits(), ([], ['fake']))

        # Verify ['fake', 'name'] ordering sends both fields to manual sort list
        dt = DT(
            [],
            '/',
            query_config={
                'order[0][column]': '1',
                'order[0][dir]': 'asc',
                'order[1][column]': '0',
                'order[1][dir]': 'asc'
            })  # 'iSortingCols': '2',
        dt.configure()
        self.assertEqual(dt.get_ordering_splits(), ([], ['fake', 'name']))
 def test_normalize_config(self):
     dt = Datatable([], '/')
     dt.configure()
     self.assertEqual(dt.config['hidden_columns'], [])
     self.assertEqual(dt.config['search_fields'], [])
     self.assertEqual(dt.config['unsortable_columns'], [])
     self.assertEqual(dt.config['search'], set())
     self.assertEqual(dt.config['start_offset'], 0)
     self.assertEqual(dt.config['page_length'], 25)
     self.assertEqual(dt.config['ordering'], None)
Esempio n. 3
0
 def test_normalize_config(self):
     dt = Datatable([], "/")
     dt.configure()
     self.assertEqual(dt.config["hidden_columns"], [])
     self.assertEqual(dt.config["search_fields"], [])
     self.assertEqual(dt.config["unsortable_columns"], [])
     self.assertEqual(dt.config["search"], set())
     self.assertEqual(dt.config["start_offset"], 0)
     self.assertEqual(dt.config["page_length"], 25)
     self.assertEqual(dt.config["ordering"], None)