Fixing tests to compared with no whitespace

This commit is contained in:
Alex Kahan 2016-10-04 09:08:08 -04:00
parent 567371bb2e
commit 183ea123ae

View File

@ -12,6 +12,15 @@ from rest_framework.test import APIRequestFactory
factory = APIRequestFactory() factory = APIRequestFactory()
def format_html(html):
"""
Helper function that formats HTML in order for easier comparison
:param html: raw HTML text to be formatted
:return: Cleaned HTML with no newlines or spaces
"""
return html.replace('\n', '').replace(' ', '')
class TemplateTagTests(TestCase): class TemplateTagTests(TestCase):
def test_add_query_param_with_non_latin_character(self): def test_add_query_param_with_non_latin_character(self):
@ -50,15 +59,50 @@ class TemplateTagTests(TestCase):
Tests format_value with a list of lists/dicts Tests format_value with a list of lists/dicts
""" """
list_of_lists = [['list1'], ['list2'], ['list3']] list_of_lists = [['list1'], ['list2'], ['list3']]
expected_list_format = """
<tableclass="tabletable-striped">
<tbody>
<tr>
<th>0</th>
<td>list1</td>
</tr>
<tr>
<th>1</th>
<td>list2</td>
</tr>
<tr>
<th>2</th>
<td>list3</td>
</tr>
</tbody>
</table>"""
self.assertEqual( self.assertEqual(
format_value(list_of_lists).replace(' ', ''), format_html(format_value(list_of_lists)),
'\n<tableclass="tabletable-striped">\n<tbody>\n\n<tr>\n<th>0</th>\n<td>\nlist1\n</td>\n</tr>\n\n<tr>\n<th>1</th>\n<td>\nlist2\n</td>\n</tr>\n\n<tr>\n<th>2</th>\n<td>\nlist3\n</td>\n</tr>\n\n</tbody>\n</table>\n' format_html(expected_list_format)
) )
expected_dict_format = """
<tableclass="tabletable-striped">
<tbody>
<tr>
<th>0</th>
<td></td>
</tr>
<tr>
<th>1</th>
<td></td>
</tr>
<tr>
<th>2</th>
<td></td>
</tr>
</tbody>
</table>"""
list_of_dicts = [{'item1': 'value1'}, {'item2': 'value2'}, {'item3': 'value3'}] list_of_dicts = [{'item1': 'value1'}, {'item2': 'value2'}, {'item3': 'value3'}]
self.assertEqual( self.assertEqual(
format_value(list_of_dicts).replace(' ', ''), format_html(format_value(list_of_dicts)),
'\n<tableclass="tabletable-striped">\n<tbody>\n\n<tr>\n<th>0</th>\n<td></td>\n</tr>\n\n<tr>\n<th>1</th>\n<td></td>\n</tr>\n\n<tr>\n<th>2</th>\n<td></td>\n</tr>\n\n</tbody>\n</table>\n' format_html(expected_dict_format)
) )
def test_format_value_simple_string(self): def test_format_value_simple_string(self):