Skip to content

Commit 728224b

Browse files
committed
Merge pull request iommirocks#63 in COMMON/tri.table from feature/mutmut-round to master
* commit '95678ff90015c7dedef8116d9a91cae89a52c5b6': A round of mutmut
2 parents da6b2bf + 95678ff commit 728224b

File tree

4 files changed

+67
-7
lines changed

4 files changed

+67
-7
lines changed

lib/tri/table/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ def order_by_on_list(objects, order_field, is_desc=False):
8181

8282
def yes_no_formatter(value, **_):
8383
""" Handle True/False from Django model and 1/0 from raw sql """
84-
if value is True or value == 1:
84+
if value is None:
85+
return ''
86+
if value == 1: # boolean True is equal to 1
8587
return 'Yes'
86-
if value is False or value == 0:
88+
if value == 0: # boolean False is equal to 0
8789
return 'No'
88-
if value is None: # pragma: no cover
89-
return ''
9090
assert False, "Unable to convert {} to Yes/No".format(value) # pragma: no cover # pragma: no mutate
9191

9292

@@ -874,7 +874,6 @@ def render_css_class(self):
874874

875875
group_columns.append(GroupColumn(
876876
display_name=group_name,
877-
sortable=False,
878877
colspan=len(columns_in_group),
879878
attrs__class__superheader=True,
880879
))
@@ -1163,7 +1162,7 @@ def render_table(request,
11631162
template_name='tri_table/list.html', # deprecated
11641163
template=None,
11651164
blank_on_empty=False,
1166-
paginate_by=40,
1165+
paginate_by=40, # pragma: no mutate
11671166
page=None,
11681167
context_processors=None,
11691168
paginator=None,
@@ -1242,7 +1241,7 @@ def render_table(request,
12421241
hit_label=hit_label,
12431242
)
12441243

1245-
if not table.data and blank_on_empty: # pragma: no cover
1244+
if not table.data and blank_on_empty:
12461245
return ''
12471246

12481247
if table.query_form and not table.query_form.is_valid():

tests/test_paginator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
from tri.table.templatetags.tri_table import paginator
3+
from tri.struct import merged
4+
5+
expected_base = dict(extra='', page_numbers=[1, 2, 3], show_first=False, show_last=True)
6+
7+
8+
@pytest.fixture
9+
def context():
10+
return dict(page=0, pages=[1, 2, 3], results_per_page=3, hits=11, next=1, previous=None, has_next=True, has_previous=False, show_hits=True, hit_label='hits')
11+
12+
13+
def test_paginator_basic(context):
14+
actual = paginator(context=context, adjacent_pages=1)
15+
expected = merged(context, **expected_base)
16+
assert actual == expected

tests/test_sort.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,38 @@ class TestTable(Table):
173173
</table>
174174
""")
175175

176+
# now reversed
177+
verify_table_html(table=TestTable(data=Foo.objects.all()),
178+
query=dict(order='-a'),
179+
expected_html="""\
180+
<table class="listview">
181+
<thead>
182+
<tr>
183+
<th class="first_column sorted_column subheader">
184+
<a href="?order=a"> A </a>
185+
</th>
186+
<th class="first_column subheader">
187+
<a href="?order=b"> B </a>
188+
</th>
189+
</tr>
190+
</thead>
191+
<tbody>
192+
<tr class="row1" data-pk="1">
193+
<td class="rj"> 4711 </td>
194+
<td> c </td>
195+
</tr>
196+
<tr class="row2" data-pk="3">
197+
<td class="rj"> 42 </td>
198+
<td> b </td>
199+
</tr>
200+
<tr class="row1" data-pk="2">
201+
<td class="rj"> 17 </td>
202+
<td> a </td>
203+
</tr>
204+
</tbody>
205+
</table>
206+
""")
207+
176208

177209
def test_order_by_on_list_nested():
178210
data = [Struct(foo=Struct(bar='c')),

tests/test_tri_table.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,15 @@ def post_bulk_edit(table, pks, queryset, updates):
724724
(4, 4, u''),
725725
]
726726

727+
# Test that empty field means "no change"
728+
render_table(request=RequestFactory(HTTP_REFERER='/').post("/", dict(pk_1='', pk_2='', a='', b='')), table=TestTable(data=Foo.objects.all()))
729+
assert [(x.pk, x.a, x.b) for x in Foo.objects.all()] == [
730+
(1, 0, u'changed'),
731+
(2, 0, u'changed'),
732+
(3, 3, u''),
733+
(4, 4, u''),
734+
]
735+
727736

728737
@pytest.mark.django_db
729738
def test_query():
@@ -1368,3 +1377,7 @@ def test_yes_no_formatter():
13681377
assert yes_no_formatter(1) == 'Yes'
13691378
assert yes_no_formatter(False) == 'No'
13701379
assert yes_no_formatter(0) == 'No'
1380+
1381+
1382+
def test_blank_on_empty():
1383+
assert render_table(RequestFactory().get('/'), table=Table(data=[], columns=[Column(name='foo')]), blank_on_empty=True) == ''

0 commit comments

Comments
 (0)