]> gitweb.fperrin.net Git - djsite.git/commitdiff
Repair the /all/ page
authorFrédéric Perrin <frederic.perrin@resel.fr>
Fri, 30 Sep 2016 23:43:49 +0000 (23:43 +0000)
committerFrédéric Perrin <frederic.perrin@resel.fr>
Fri, 30 Sep 2016 23:43:49 +0000 (23:43 +0000)
quotes/templates/quotes/all.html [new file with mode: 0644]
quotes/tests.py

diff --git a/quotes/templates/quotes/all.html b/quotes/templates/quotes/all.html
new file mode 100644 (file)
index 0000000..f15296f
--- /dev/null
@@ -0,0 +1,11 @@
+{% extends 'quotes/base.html' %}
+
+{% block title %}All the quotes in the database{% endblock %}
+
+{% block body %}
+
+{% for quote in quotes %}
+  {% include "quotes/display.html" with quote=quote %}
+{% endfor %}
+
+{% endblock %}
index 2a7bc4502ae84b04ce160ced0f6290c2bf03d6e7..00237fa2ec9fdfc4e30e66309f6400354cec74f4 100644 (file)
@@ -17,6 +17,13 @@ class QuoteTest(TestCase):
 
 
 class ViewsTest(TestCase):
+    def getPage(self, url, exp_status=200):
+        c = Client()
+        response = c.get('/quotes/' + url)
+        self.assertEqual(response.status_code, 200)
+        self.assertEqual(response.charset, 'utf-8')
+        return response.content.decode(response.charset)
+
     def setUp(self):
         a1 = Author.objects.create(name="Author with notes",
                                    notes="Some notes")
@@ -28,44 +35,48 @@ class ViewsTest(TestCase):
         a2 = Author.objects.create(name="Author without notes")
         q2= Quote.objects.create(text="Quote02, no tags", author=a2)
 
+    def test_all(self):
+        content = self.getPage('all/')
+        for a in Author.objects.all():
+            self.assertTrue(a.name in content)
+        for q in Quote.objects.all():
+            self.assertTrue(q.text in content)
+
     def test_views_all_data(self):
         q = Quote.objects.filter(text__startswith="Quote01")
         self.assertEqual(q.count(), 1)
         q = q[0]
 
-        c = Client()
-        response = c.get('/quotes/show/%s/' % q.id)
-        self.assertEqual(response.status_code, 200)
-        self.assertTrue('Quote01, two tags' in response.content)
-        self.assertTrue("author_notes" in response.content)
-        self.assertEqual(response.content.count("tag_link"), 2)
+        # check the individual quote page
+        quotepage = self.getPage('show/%s/' % q.id)
+        self.assertTrue(q.text in quotepage)
+        self.assertTrue("author_notes" in quotepage)
+        self.assertEqual(quotepage.count("tag_link"), 2)
 
-        response = c.get('/quotes/author/%s/' % q.author.id)
-        self.assertEqual(response.status_code, 200)
-        self.assertTrue('Quote01, two tags' in response.content)
-        self.assertTrue("author_notes" in response.content)
+        # check the author page
+        authorpage = self.getPage('author/%s/' % q.author.id)
+        self.assertTrue(q.text in authorpage)
+        self.assertTrue("author_notes" in authorpage)
 
+        # check the tag page
         for tag in q.tags.all():
-            response = c.get('/quotes/tag/%s/' % tag.id)
-            self.assertEqual(response.status_code, 200)
-            self.assertTrue('Quote01, two tags' in response.content)
+            tagpage = self.getPage('tag/%s/' % tag.id)
+            self.assertTrue(q.text in tagpage)
 
     def test_views_minimal_data(self):
         q = Quote.objects.filter(text__startswith="Quote02")
         self.assertEqual(q.count(), 1)
         q = q[0]
 
-        c = Client()
-        response = c.get('/quotes/show/%s/' % q.id)
-        self.assertEqual(response.status_code, 200)
-        self.assertTrue('Quote02' in response.content)
-        self.assertFalse("author_notes" in response.content)
-        self.assertEqual(response.content.count("tag_link"), 0)
+        quotepage = self.getPage('show/%s/' % q.id)
+        self.assertTrue(q.text in quotepage)
+        self.assertFalse("author_notes" in quotepage)
+        self.assertEqual(quotepage.count("tag_link"), 0)
 
-        response = c.get('/quotes/author/%s/' % q.author.id)
-        self.assertEqual(response.status_code, 200)
-        self.assertFalse('Quote01, two tags' in response.content)
-        self.assertTrue('Quote02' in response.content)
+        authorpage = self.getPage('author/%s/' % q.author.id)
+        self.assertTrue(q.text in authorpage)
+        self.assertFalse("author_notes" in authorpage)
+        self.assertFalse('Quote01, two tags' in authorpage)        
 
     def test_view_author_notes_once(self):
         # check that on the per-author view, the author notes aren't display
@@ -74,7 +85,5 @@ class ViewsTest(TestCase):
         self.assertEqual(a.count(), 1)
         a = a[0]
 
-        c = Client()
-        response = c.get('/quotes/author/%s/' % a.id)
-        self.assertEqual(response.status_code, 200)
-        self.assertEqual(response.content.count("Some notes"), 1)
+        authorpage = self.getPage('author/%s/' % a.id)
+        self.assertEqual(authorpage.count("Some notes"), 1)