Added a utility function to show just the text content of the test client response.
- Legacy-Id: 13737
This commit is contained in:
parent
60e9b7451c
commit
db96292229
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue