X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;ds=sidebyside;f=quotes%2Ftests.py;h=00237fa2ec9fdfc4e30e66309f6400354cec74f4;hb=f978cf95dcb4b6f1d6d81e94b504d360d2489f54;hp=556e9252c3377477911b077da4e64315b8f067b9;hpb=af3f857eea25b939f927832741f377e4de401f9c;p=djsite.git diff --git a/quotes/tests.py b/quotes/tests.py index 556e925..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,41 +35,55 @@ 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 + # for every quote + a = Author.objects.filter(name="Author with notes") + self.assertEqual(a.count(), 1) + a = a[0] + + authorpage = self.getPage('author/%s/' % a.id) + self.assertEqual(authorpage.count("Some notes"), 1)