From: Frédéric Perrin Date: Fri, 30 Sep 2016 23:43:49 +0000 (+0000) Subject: Repair the /all/ page X-Git-Url: http://gitweb.fperrin.net/?p=djsite.git;a=commitdiff_plain;h=f978cf95dcb4b6f1d6d81e94b504d360d2489f54 Repair the /all/ page --- diff --git a/quotes/templates/quotes/all.html b/quotes/templates/quotes/all.html new file mode 100644 index 0000000..f15296f --- /dev/null +++ b/quotes/templates/quotes/all.html @@ -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 %} diff --git a/quotes/tests.py b/quotes/tests.py index 2a7bc45..00237fa 100644 --- a/quotes/tests.py +++ b/quotes/tests.py @@ -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)