7 class ValidatingClient(object):
8 def __init__(self, client):
11 def request(self, url, method, exp_status=200, params={}):
12 if not url.startswith('/quotes/'):
13 url = '/quotes/' + url
16 response = self.client.get(url)
17 elif method == 'post':
18 response = self.client.post(url, params)
20 raise RuntimeError('Unknown method %s for %s' % (method, url))
21 assert response.status_code == exp_status
22 if response.status_code != 200:
24 assert response.charset == 'utf-8'
25 document = response.content.decode(response.charset)
26 print 'For url %s got page:\n%s' % (url, document)
27 lxml.etree.fromstring(document.replace('<br>', '<br/>'))
29 parser = html5lib.HTMLParser(strict=True)
30 parser.parse(document)
32 assert '<script>' not in document
35 def getPage(self, url, exp_status=200):
36 return self.request(url, 'get', exp_status=exp_status)
38 def postPage(self, url, params, exp_status=200):
39 return self.request(url, 'post', params=params, exp_status=exp_status)
41 def checkAllLinks(self, url, document):
42 tree = lxml.etree.fromstring(document)
43 links = tree.xpath("//a")
45 href = link.attrib['href']
48 fullurl = urlparse.urljoin(url, href)
49 print "asking for fullurl=", fullurl
50 assert self.getPage(fullurl)
54 return ValidatingClient(client)
57 def c_adm(admin_client):
58 return ValidatingClient(admin_client)