import pytest
import lxml.etree
+import html5lib
+import urlparse
class ValidatingClient(object):
def __init__(self, client):
self.client = client
-
+
def request(self, url, method, exp_status=200, params={}):
if not url.startswith('/quotes/'):
url = '/quotes/' + url
document = response.content.decode(response.charset)
print 'For url %s got page:\n%s' % (url, document)
lxml.etree.fromstring(document.replace('<br>', '<br/>'))
+
+ parser = html5lib.HTMLParser(strict=True)
+ parser.parse(document)
+
assert '<script>' not in document
return document
def postPage(self, url, params, exp_status=200):
return self.request(url, 'post', params=params, exp_status=exp_status)
+ def checkAllLinks(self, url, document):
+ tree = lxml.etree.fromstring(document)
+ links = tree.xpath("//a")
+ for link in links:
+ href = link.attrib['href']
+ if href == '#':
+ continue
+ fullurl = urlparse.urljoin(url, href)
+ print "asking for fullurl=", fullurl
+ assert self.getPage(fullurl)
+
@pytest.fixture
def c(client):
return ValidatingClient(client)
— <span class="name">
<a href="{{ quote.work.author.get_absolute_url }}"
class="author_name">{{ quote.work.author.name }}</a>,
- <a href="{% quote.work.get_absolute_url }}"
+ <a href="{{ quote.work.get_absolute_url }}"
class="work_name">{{ quote.work.name }}</a>
</span>
</p>
cloud = c.getPage("cloud/")
for size in top20:
assert re.search("tag-%d-, %d quotes" % (size, size), cloud)
+ c.checkAllLinks('cloud/', cloud)
def test_cloud(self, size_range_small, db, c):
self.fill_db(size_range_small)