]> gitweb.fperrin.net Git - djsite.git/blobdiff - quotes/tests.py
Add testing for the 'random' page
[djsite.git] / quotes / tests.py
index 3836f4e5e829dce28360b52e25235f0b2215dc40..772d4e3491d90f143de4b1cdab5d22107dd81c32 100644 (file)
@@ -1,8 +1,8 @@
-import sys
 from django.test import TestCase, Client
 
 # Create your tests here.
 from .models import Tag, Author, Work, Quote
+import re
 
 class QuoteTest(TestCase):
     def setUp(self):
@@ -53,6 +53,24 @@ class ViewsTest(TestCase):
             self.assertTrue(q.text in content, content)
             self.assertTrue(q.notes in content, content)
 
+    def test_random(self):
+        seen = {}
+        for q in Quote.objects.all():
+            seen[q.id] = False
+
+        # <a href="{% url 'quotes:onequote' quote.id %}">Permalink</a>
+        permalinkre = re.compile(r'([0-9]+).*Permalink')
+
+        for i in xrange(100):
+            content = self.getPage('random')
+            m = permalinkre.search(content)
+            self.assertIsNotNone(m, content)
+            quoteid = int(m.group(1))
+            self.assertIn(quoteid, seen)
+            seen[quoteid] = True
+        for q in Quote.objects.all():
+            self.assertTrue(seen[q.id])
+
     def test_views_all_data(self):
         q = Quote.objects.filter(text__startswith="Quote01")
         self.assertEqual(q.count(), 1)