Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ef8e34

Browse files
committed
Cleanup column tests a bit more
1 parent f72eaac commit 3ef8e34

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

tests/columns/test_booleancolumn.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ class Meta:
132132
Occupation.objects.create(name='Onwaar', boolean=False),
133133
Occupation.objects.create(name='Onduidelijk')
134134

135-
table = Table(Occupation.objects.all())
136-
137-
html = table.as_html(build_request())
135+
html = Table(Occupation.objects.all()).as_html(build_request())
138136

139137
assert 'Waar' in html
140138
assert 'Onwaar' in html

tests/columns/test_general.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# coding: utf-8
22
from __future__ import unicode_literals
33

4+
import pytest
45
from django.db import models
56
from django.utils.safestring import SafeData, mark_safe
67
from django.utils.translation import ugettext_lazy
78

89
import django_tables2 as tables
9-
import pytest
1010

1111
from ..app.models import Person
1212
from ..utils import build_request, parse
@@ -158,10 +158,10 @@ class SimpleTable(tables.Table):
158158

159159

160160
def test_translation():
161-
"""
161+
'''
162162
Tests different types of values for the ``verbose_name`` property of a
163163
column.
164-
"""
164+
'''
165165
class TranslationTable(tables.Table):
166166
text = tables.Column(verbose_name=ugettext_lazy('Text'))
167167

@@ -170,9 +170,9 @@ class TranslationTable(tables.Table):
170170

171171

172172
def test_sequence():
173-
"""
173+
'''
174174
Ensures that the sequence of columns is configurable.
175-
"""
175+
'''
176176
class TestTable(tables.Table):
177177
a = tables.Column()
178178
b = tables.Column()
@@ -235,11 +235,11 @@ class TestTable9(TestTable):
235235

236236

237237
def test_should_support_both_meta_sequence_and_constructor_exclude():
238-
"""
238+
'''
239239
Issue #32 describes a problem when both ``Meta.sequence`` and
240240
``Table(..., exclude=...)`` are used on a single table. The bug caused an
241241
exception to be raised when the table was iterated.
242-
"""
242+
'''
243243
class SequencedTable(tables.Table):
244244
a = tables.Column()
245245
b = tables.Column()
@@ -420,7 +420,6 @@ def get_column_class_names(self, classes_set, bound_column):
420420
{'name': 'France', 'population': 66000000},
421421
]
422422

423-
table = MyTable(TEST_DATA)
424-
html = table.as_html(build_request())
423+
html = MyTable(TEST_DATA).as_html(build_request())
425424

426425
assert '<td class="prefix-population">11200000</td>' in html

tests/columns/test_linkcolumn.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ class UnicodeTable(tables.Table):
3030
{'pk': 2, 'first_name': 'Chr…s', 'last_name': 'DÒble'},
3131
]
3232

33-
table = UnicodeTable(dataset)
34-
request = build_request('/some-url/')
3533
template = Template('{% load django_tables2 %}{% render_table table %}')
36-
html = template.render(Context({'request': request, 'table': table}))
34+
html = template.render(Context({
35+
'request': build_request(),
36+
'table': UnicodeTable(dataset)
37+
}))
3738

3839
assert 'Brädley' in html
3940
assert '∆yers' in html
@@ -54,8 +55,7 @@ class CustomLinkTable(tables.Table):
5455
{'pk': 1, 'first_name': 'John', 'last_name': 'Doe'}
5556
]
5657

57-
table = CustomLinkTable(dataset)
58-
html = table.as_html(build_request('/some-url/'))
58+
html = CustomLinkTable(dataset).as_html(build_request())
5959

6060
assert 'foo::bar' in html
6161
assert 'Doe John' in html
@@ -73,8 +73,7 @@ class CustomLinkTable(tables.Table):
7373
{'pk': 1, 'first_name': 'John', 'last_name': 'Doe'}
7474
]
7575

76-
table = CustomLinkTable(dataset)
77-
html = table.as_html(build_request('/some-url/'))
76+
html = CustomLinkTable(dataset).as_html(build_request())
7877

7978
expected = '<td class="editlink"><a href="{}">edit</a></td>'.format(
8079
reverse('person', args=(1, ))
@@ -118,10 +117,10 @@ def test_kwargs():
118117
class PersonTable(tables.Table):
119118
a = tables.LinkColumn('occupation', kwargs={'pk': A('a')})
120119

121-
request = build_request('/')
122-
html = PersonTable([{'a': 0}, {'a': 1}]).as_html(request)
123-
assert reverse('occupation', kwargs={'pk': 0}) in html
124-
assert reverse('occupation', kwargs={'pk': 1}) in html
120+
table = PersonTable([{'a': 0}, {'a': 1}])
121+
122+
assert reverse('occupation', kwargs={'pk': 0}) in table.rows[0].get_cell('a')
123+
assert reverse('occupation', kwargs={'pk': 1}) in table.rows[1].get_cell('a')
125124

126125

127126
def test_html_escape_value():
@@ -201,6 +200,10 @@ class PersonTable(tables.Table):
201200

202201

203202
def test_get_absolute_url_not_defined():
203+
'''
204+
The dict doesn't have a get_absolute_url(), so creating the table should
205+
raise a TypeError
206+
'''
204207
class Table(tables.Table):
205208
first_name = tables.Column()
206209
last_name = tables.LinkColumn()
@@ -210,7 +213,7 @@ class Table(tables.Table):
210213
])
211214

212215
with pytest.raises(TypeError):
213-
table.as_html(build_request('/'))
216+
table.as_html(build_request())
214217

215218

216219
@pytest.mark.django_db

0 commit comments

Comments
 (0)