]> gitweb.fperrin.net Git - djsite.git/blobdiff - quotes/conftest.py
Fix link to work page
[djsite.git] / quotes / conftest.py
index b87a6baf2a756894143ec20c6f2db398144f8f01..26ac8efe0b44e9db997681542358e62e7c125349 100644 (file)
@@ -1,11 +1,13 @@
 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
@@ -21,7 +23,12 @@ class ValidatingClient(object):
             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
 
@@ -31,6 +38,17 @@ class ValidatingClient(object):
     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)