From db96292229585e7d6470aab8a94e24abb769eedc Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Fri, 30 Jun 2017 11:45:24 +0000 Subject: [PATCH] Added a utility function to show just the text content of the test client response. - Legacy-Id: 13737 --- ietf/utils/test_utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ietf/utils/test_utils.py b/ietf/utils/test_utils.py index 6e240f763..936e2a16c 100644 --- a/ietf/utils/test_utils.py +++ b/ietf/utils/test_utils.py @@ -33,9 +33,11 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import os +import re import html5lib import urllib2 from unittest.util import strclass +from bs4 import BeautifulSoup import django.test from django.conf import settings @@ -66,6 +68,11 @@ def unicontent(r): "Return a HttpResponse object's content as unicode" return r.content.decode(r.charset) +def textcontent(r): + text = BeautifulSoup(r.content, 'lxml').get_text() + text = re.sub('(\n\s+){2,}', '\n\n', text) + return text + def reload_db_objects(*objects): """Rerequest the given arguments from the database so they're refreshed, to be used like @@ -133,4 +140,4 @@ class TestCase(django.test.TestCase): def __str__(self): return "%s (%s.%s)" % (self._testMethodName, strclass(self.__class__),self._testMethodName) - \ No newline at end of file +