]> gitweb.fperrin.net Git - djsite.git/blobdiff - quotes/tests.py
Validate all pages in tests
[djsite.git] / quotes / tests.py
index fe7e0a80456ac99edd9adbe959ecb4dce352e7a5..2d75e321334ae7b07f3894ae964b87a3992e6ef6 100644 (file)
@@ -3,17 +3,20 @@ from django.test import TestCase, Client
 # Create your tests here.
 from .models import Tag, Author, Work, Quote
 import re
+import lxml.etree
 
 class QuoteTest(TestCase):
     def setUp(self):
         a1 = Author.objects.create(name="JFK")
         w1 = Work.objects.create(name="Berlin speech", author=a1)
         q1 = Quote.objects.create(text="Ich bin...", work=w1)
+        self.q1 = q1
 
     def test_one(self):
         q = Quote.objects.filter(text__startswith="Ich")
         self.assertEqual(q.count(), 1)
         q = q[0]
+        self.assertEqual(q, self.q1)
         self.assertEqual(q.work.author.name, "JFK")
 
 class ViewsTest(TestCase):
@@ -22,7 +25,12 @@ class ViewsTest(TestCase):
         response = c.get('/quotes/' + url)
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.charset, 'utf-8')
-        return response.content.decode(response.charset)
+        document = response.content.decode(response.charset)
+        try:
+            lxml.etree.fromstring(document)
+        except lxml.etree.XMLSyntaxError as e:
+            self.assertTrue(False, 'Errors in page at %s: %s' % (url, e))
+        return document
 
     def setUp(self):
         a1 = Author.objects.create(name="Author with notes",
@@ -62,7 +70,7 @@ class ViewsTest(TestCase):
         # <a href="{% url 'quotes:onequote' quote.id %}">Permalink</a>
         permalinkre = re.compile(r'([0-9]+).*Permalink')
 
-        for i in xrange(100):
+        for i in range(100):
             content = self.getPage('random')
             m = permalinkre.search(content)
             self.assertIsNotNone(m, content)