Skip to content

Commit bc33f22

Browse files
committed
Added a test for Harro's columns= sorting change.
1 parent 836ddf5 commit bc33f22

File tree

1 file changed

+51
-38
lines changed

1 file changed

+51
-38
lines changed

tests/test_models.py

Lines changed: 51 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -52,45 +52,57 @@ class Meta:
5252
Country(name="Netherlands", tld="nl", population=16, system="monarchy", capital=amsterdam).save()
5353

5454

55-
def test_declaration():
55+
class TestDeclaration:
5656
"""Test declaration, declared columns and default model field columns.
57-
"""
58-
59-
class CountryTable(tables.ModelTable):
60-
class Meta:
61-
model = Country
62-
63-
assert len(CountryTable.base_columns) == 8
64-
assert 'name' in CountryTable.base_columns
65-
assert not hasattr(CountryTable, 'name')
66-
67-
# Override one model column, add another custom one, exclude one
68-
class CountryTable(tables.ModelTable):
69-
capital = tables.TextColumn(verbose_name='Name of capital')
70-
projected = tables.Column(verbose_name="Projected Population")
71-
class Meta:
72-
model = Country
73-
exclude = ['tld']
74-
75-
assert len(CountryTable.base_columns) == 8
76-
assert 'projected' in CountryTable.base_columns
77-
assert 'capital' in CountryTable.base_columns
78-
assert not 'tld' in CountryTable.base_columns
79-
80-
# Inheritance (with a different model) + field restrictions
81-
class CityTable(CountryTable):
82-
class Meta:
83-
model = City
84-
columns = ['id', 'name']
85-
exclude = ['capital']
86-
87-
print CityTable.base_columns
88-
assert len(CityTable.base_columns) == 4
89-
assert 'id' in CityTable.base_columns
90-
assert 'name' in CityTable.base_columns
91-
assert 'projected' in CityTable.base_columns # declared in parent
92-
assert not 'population' in CityTable.base_columns # not in Meta:columns
93-
assert 'capital' in CityTable.base_columns # in exclude, but only works on model fields (is that the right behaviour?)
57+
"""
58+
59+
def test_autogen_basic(self):
60+
class CountryTable(tables.ModelTable):
61+
class Meta:
62+
model = Country
63+
64+
assert len(CountryTable.base_columns) == 8
65+
assert 'name' in CountryTable.base_columns
66+
assert not hasattr(CountryTable, 'name')
67+
68+
# Override one model column, add another custom one, exclude one
69+
class CountryTable(tables.ModelTable):
70+
capital = tables.TextColumn(verbose_name='Name of capital')
71+
projected = tables.Column(verbose_name="Projected Population")
72+
class Meta:
73+
model = Country
74+
exclude = ['tld']
75+
76+
assert len(CountryTable.base_columns) == 8
77+
assert 'projected' in CountryTable.base_columns
78+
assert 'capital' in CountryTable.base_columns
79+
assert not 'tld' in CountryTable.base_columns
80+
81+
# Inheritance (with a different model) + field restrictions
82+
class CityTable(CountryTable):
83+
class Meta:
84+
model = City
85+
columns = ['id', 'name']
86+
exclude = ['capital']
87+
88+
print CityTable.base_columns
89+
assert len(CityTable.base_columns) == 4
90+
assert 'id' in CityTable.base_columns
91+
assert 'name' in CityTable.base_columns
92+
assert 'projected' in CityTable.base_columns # declared in parent
93+
assert not 'population' in CityTable.base_columns # not in Meta:columns
94+
assert 'capital' in CityTable.base_columns # in exclude, but only works on model fields (is that the right behaviour?)
95+
96+
def test_columns_custom_order(self):
97+
"""Using the columns meta option, you can also modify the ordering.
98+
"""
99+
class CountryTable(tables.ModelTable):
100+
foo = tables.Column()
101+
class Meta:
102+
model = Country
103+
columns = ('system', 'population', 'foo', 'tld',)
104+
105+
assert [c.name for c in CountryTable().columns] == ['system', 'population', 'foo', 'tld']
94106

95107

96108
def test_basic():
@@ -140,6 +152,7 @@ class CountryTable(tables.ModelTable):
140152
tld = tables.Column(name="domain")
141153
countries = CountryTable(Country)
142154
test_country_table(countries)
155+
143156

144157
def test_caches():
145158
"""Make sure the caches work for model tables as well (parts are

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy