]> gitweb.fperrin.net Git - djsite.git/blobdiff - quotes/conftest.py
Fix link to work page
[djsite.git] / quotes / conftest.py
index 5cdf30a8431f17093e24322ca3e8ba8892103adb..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
@@ -17,18 +19,40 @@ class ValidatingClient(object):
         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)