@@ -52,45 +52,57 @@ class Meta:
52
52
Country (name = "Netherlands" , tld = "nl" , population = 16 , system = "monarchy" , capital = amsterdam ).save ()
53
53
54
54
55
- def test_declaration () :
55
+ class TestDeclaration :
56
56
"""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' ]
94
106
95
107
96
108
def test_basic ():
@@ -140,6 +152,7 @@ class CountryTable(tables.ModelTable):
140
152
tld = tables .Column (name = "domain" )
141
153
countries = CountryTable (Country )
142
154
test_country_table (countries )
155
+
143
156
144
157
def test_caches ():
145
158
"""Make sure the caches work for model tables as well (parts are
0 commit comments