@@ -30,10 +30,11 @@ class UnicodeTable(tables.Table):
30
30
{'pk' : 2 , 'first_name' : 'Chr…s' , 'last_name' : 'DÒble' },
31
31
]
32
32
33
- table = UnicodeTable (dataset )
34
- request = build_request ('/some-url/' )
35
33
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
+ }))
37
38
38
39
assert 'Brädley' in html
39
40
assert '∆yers' in html
@@ -54,8 +55,7 @@ class CustomLinkTable(tables.Table):
54
55
{'pk' : 1 , 'first_name' : 'John' , 'last_name' : 'Doe' }
55
56
]
56
57
57
- table = CustomLinkTable (dataset )
58
- html = table .as_html (build_request ('/some-url/' ))
58
+ html = CustomLinkTable (dataset ).as_html (build_request ())
59
59
60
60
assert 'foo::bar' in html
61
61
assert 'Doe John' in html
@@ -73,8 +73,7 @@ class CustomLinkTable(tables.Table):
73
73
{'pk' : 1 , 'first_name' : 'John' , 'last_name' : 'Doe' }
74
74
]
75
75
76
- table = CustomLinkTable (dataset )
77
- html = table .as_html (build_request ('/some-url/' ))
76
+ html = CustomLinkTable (dataset ).as_html (build_request ())
78
77
79
78
expected = '<td class="editlink"><a href="{}">edit</a></td>' .format (
80
79
reverse ('person' , args = (1 , ))
@@ -118,10 +117,10 @@ def test_kwargs():
118
117
class PersonTable (tables .Table ):
119
118
a = tables .LinkColumn ('occupation' , kwargs = {'pk' : A ('a' )})
120
119
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' )
125
124
126
125
127
126
def test_html_escape_value ():
@@ -201,6 +200,10 @@ class PersonTable(tables.Table):
201
200
202
201
203
202
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
+ '''
204
207
class Table (tables .Table ):
205
208
first_name = tables .Column ()
206
209
last_name = tables .LinkColumn ()
@@ -210,7 +213,7 @@ class Table(tables.Table):
210
213
])
211
214
212
215
with pytest .raises (TypeError ):
213
- table .as_html (build_request ('/' ))
216
+ table .as_html (build_request ())
214
217
215
218
216
219
@pytest .mark .django_db
0 commit comments