Skip to content

Commit db96292

Browse files
committed
Added a utility function to show just the text content of the test client response.
- Legacy-Id: 13737
1 parent 60e9b74 commit db96292

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ietf/utils/test_utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434

3535
import os
36+
import re
3637
import html5lib
3738
import urllib2
3839
from unittest.util import strclass
40+
from bs4 import BeautifulSoup
3941

4042
import django.test
4143
from django.conf import settings
@@ -66,6 +68,11 @@ def unicontent(r):
6668
"Return a HttpResponse object's content as unicode"
6769
return r.content.decode(r.charset)
6870

71+
def textcontent(r):
72+
text = BeautifulSoup(r.content, 'lxml').get_text()
73+
text = re.sub('(\n\s+){2,}', '\n\n', text)
74+
return text
75+
6976
def reload_db_objects(*objects):
7077
"""Rerequest the given arguments from the database so they're refreshed, to be used like
7178
@@ -133,4 +140,4 @@ def assertNoFormPostErrors(self, response, error_css_selector=".has-error"):
133140
def __str__(self):
134141
return "%s (%s.%s)" % (self._testMethodName, strclass(self.__class__),self._testMethodName)
135142

136-
143+

0 commit comments

Comments
 (0)