]> gitweb.fperrin.net Git - djsite.git/commitdiff
Fix link to work page
authorFrédéric Perrin <frederic.perrin@resel.fr>
Fri, 11 Nov 2016 19:26:10 +0000 (19:26 +0000)
committerFrédéric Perrin <frederic.perrin@resel.fr>
Fri, 11 Nov 2016 19:26:10 +0000 (19:26 +0000)
Add testing for broken links

quotes/conftest.py
quotes/templates/quotes/display.html
quotes/test_cloud.py
quotes/test_quotes.py

index 9210e6aeb60a2049e2837372fda0ff9fffe8bd05..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
@@ -23,6 +25,10 @@ class ValidatingClient(object):
         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
 
@@ -32,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)
index 2db4c572c2a38dccf5c48d079a182d24d6873472..878c4dc13392141f0037622089a216cf974b592f 100644 (file)
@@ -10,7 +10,7 @@
        — <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>
index 906aa5bda9d58e77fb0f3f94abe5d04f18d6a9bc..b7c301174a5563a29a9628ba386da8c9c0e8025d 100644 (file)
@@ -31,6 +31,7 @@ class Test_Cloud(object):
         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)
index b4c79159cd911f2db112b1021ec7599489f58c7f..b194ec111e3f18d1c73bb9817de038df8957c0bc 100644 (file)
@@ -51,6 +51,8 @@ class Test_Views():
             assert q.text in content
             assert q.notes in content
 
+        c.checkAllLinks('all/', content)
+
     @pytest.mark.slow
     def test_random(self, c):
         seen = {}