Country(name="Netherlands", tld="nl", population=16, system="monarchy", capital=amsterdam).save()\r
\r
\r
-def test_declaration():\r
+class TestDeclaration:\r
"""Test declaration, declared columns and default model field columns.\r
- """\r
-\r
- class CountryTable(tables.ModelTable):\r
- class Meta:\r
- model = Country\r
-\r
- assert len(CountryTable.base_columns) == 8\r
- assert 'name' in CountryTable.base_columns\r
- assert not hasattr(CountryTable, 'name')\r
-\r
- # Override one model column, add another custom one, exclude one\r
- class CountryTable(tables.ModelTable):\r
- capital = tables.TextColumn(verbose_name='Name of capital')\r
- projected = tables.Column(verbose_name="Projected Population")\r
- class Meta:\r
- model = Country\r
- exclude = ['tld']\r
-\r
- assert len(CountryTable.base_columns) == 8\r
- assert 'projected' in CountryTable.base_columns\r
- assert 'capital' in CountryTable.base_columns\r
- assert not 'tld' in CountryTable.base_columns\r
-\r
- # Inheritance (with a different model) + field restrictions\r
- class CityTable(CountryTable):\r
- class Meta:\r
- model = City\r
- columns = ['id', 'name']\r
- exclude = ['capital']\r
-\r
- print CityTable.base_columns\r
- assert len(CityTable.base_columns) == 4\r
- assert 'id' in CityTable.base_columns\r
- assert 'name' in CityTable.base_columns\r
- assert 'projected' in CityTable.base_columns # declared in parent\r
- assert not 'population' in CityTable.base_columns # not in Meta:columns\r
- assert 'capital' in CityTable.base_columns # in exclude, but only works on model fields (is that the right behaviour?)\r
+ """
+
+ def test_autogen_basic(self):\r
+ class CountryTable(tables.ModelTable):\r
+ class Meta:\r
+ model = Country\r
+\r
+ assert len(CountryTable.base_columns) == 8\r
+ assert 'name' in CountryTable.base_columns\r
+ assert not hasattr(CountryTable, 'name')\r
+\r
+ # Override one model column, add another custom one, exclude one\r
+ class CountryTable(tables.ModelTable):\r
+ capital = tables.TextColumn(verbose_name='Name of capital')\r
+ projected = tables.Column(verbose_name="Projected Population")\r
+ class Meta:\r
+ model = Country\r
+ exclude = ['tld']\r
+\r
+ assert len(CountryTable.base_columns) == 8\r
+ assert 'projected' in CountryTable.base_columns\r
+ assert 'capital' in CountryTable.base_columns\r
+ assert not 'tld' in CountryTable.base_columns\r
+\r
+ # Inheritance (with a different model) + field restrictions\r
+ class CityTable(CountryTable):\r
+ class Meta:\r
+ model = City\r
+ columns = ['id', 'name']\r
+ exclude = ['capital']\r
+\r
+ print CityTable.base_columns\r
+ assert len(CityTable.base_columns) == 4\r
+ assert 'id' in CityTable.base_columns\r
+ assert 'name' in CityTable.base_columns\r
+ assert 'projected' in CityTable.base_columns # declared in parent\r
+ assert not 'population' in CityTable.base_columns # not in Meta:columns\r
+ assert 'capital' in CityTable.base_columns # in exclude, but only works on model fields (is that the right behaviour?)
+
+ def test_columns_custom_order(self):
+ """Using the columns meta option, you can also modify the ordering.
+ """
+ class CountryTable(tables.ModelTable):
+ foo = tables.Column()\r
+ class Meta:\r
+ model = Country
+ columns = ('system', 'population', 'foo', 'tld',)
+
+ assert [c.name for c in CountryTable().columns] == ['system', 'population', 'foo', 'tld']\r
\r
\r
def test_basic():\r
tld = tables.Column(name="domain")\r
countries = CountryTable(Country)\r
test_country_table(countries)\r
+
\r
def test_caches():\r
"""Make sure the caches work for model tables as well (parts are\r