From 183ea123ae6d6db7640f022397c5321dba783233 Mon Sep 17 00:00:00 2001 From: Alex Kahan Date: Tue, 4 Oct 2016 09:08:08 -0400 Subject: [PATCH] Fixing tests to compared with no whitespace --- tests/test_templatetags.py | 52 +++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index acfc8ab7c..28390320b 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -12,6 +12,15 @@ from rest_framework.test import 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): 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 """ list_of_lists = [['list1'], ['list2'], ['list3']] + expected_list_format = """ + + + + 0 + list1 + + + 1 + list2 + + + 2 + list3 + + + """ self.assertEqual( - format_value(list_of_lists).replace(' ', ''), - '\n\n\n\n\n0\n\nlist1\n\n\n\n\n1\n\nlist2\n\n\n\n\n2\n\nlist3\n\n\n\n\n\n' + format_html(format_value(list_of_lists)), + format_html(expected_list_format) ) + expected_dict_format = """ + + + + 0 + + + + 1 + + + + 2 + + + + """ + list_of_dicts = [{'item1': 'value1'}, {'item2': 'value2'}, {'item3': 'value3'}] self.assertEqual( - format_value(list_of_dicts).replace(' ', ''), - '\n\n\n\n\n0\n\n\n\n\n1\n\n\n\n\n2\n\n\n\n\n\n' + format_html(format_value(list_of_dicts)), + format_html(expected_dict_format) ) def test_format_value_simple_string(self):