From 37cbd46756cb9aff9b24fb51714c4776a43d89f4 Mon Sep 17 00:00:00 2001 From: Anthony Monthe Date: Wed, 17 Jan 2018 01:00:03 +0000 Subject: [PATCH] Added table_factory tests --- django_tables2/tables.py | 7 +++---- tests/test_models.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/django_tables2/tables.py b/django_tables2/tables.py index e9770967..c1eb30c8 100644 --- a/django_tables2/tables.py +++ b/django_tables2/tables.py @@ -622,15 +622,14 @@ class Table(TableBase): # Table = DeclarativeColumnsMetaclass(str('Table'), (TableBase, ), {}) -def table_factory(model, table=Table, fields=None, exclude=None, - localized_columns=None): +def table_factory(model, table=Table, fields=None, exclude=None, localize=None): attrs = {'model': model} if fields is not None: attrs['fields'] = fields if exclude is not None: attrs['exclude'] = exclude - if localized_columns is not None: - attrs['localized_columns'] = localized_columns + if localize is not None: + attrs['localize'] = localize # If parent form class already has an inner Meta, the Meta we're # creating needs to inherit from the parent's inner meta. parent = (object,) diff --git a/tests/test_models.py b/tests/test_models.py index 3cef25c1..f0baed4d 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -505,3 +505,28 @@ def test_factory(self): Table = tables.table_factory(Person) table = Table(persons) self.assertIsInstance(table, tables.Table) + self.assertEqual(Table.__name__, 'PersonTable') + + def test_factory_fields_argument(self): + fields = ('username',) + Table = tables.table_factory(Person, fields=fields) + self.assertEqual(Table.Meta.fields, fields) + self.assertEqual(Table._meta.fields, fields) + + def test_factory_exclude_argument(self): + exclude = ('username',) + Table = tables.table_factory(Person, exclude=exclude) + self.assertEqual(Table.Meta.exclude, exclude) + self.assertEqual(Table._meta.exclude, exclude) + + def test_factory_localize_argument(self): + localize = ('username',) + Table = tables.table_factory(Person, localize=localize) + self.assertEqual(Table.Meta.localize, localize) + self.assertEqual(Table._meta.localize, localize) + + def test_factory_with_meta(self): + localize = ('username',) + class Meta: + fields = ('first_name',) + Table = tables.table_factory(Person, localize=localize)