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
else:
raise RuntimeError('Unknown method %s for %s' % (method, url))
assert response.status_code == exp_status
+ if response.status_code != 200:
+ return None
assert response.charset == 'utf-8'
document = response.content.decode(response.charset)
- lxml.etree.fromstring(document)
+ 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 getPage(self, url):
- return self.request(url, 'get')
+ def getPage(self, url, exp_status=200):
+ return self.request(url, 'get', exp_status=exp_status)
- def postPage(self, url, params):
- return self.request(url, 'post', params=params)
+ 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)
+
+@pytest.fixture
+def c_adm(admin_client):
+ return ValidatingClient(admin_client)