]> gitweb.fperrin.net Git - djsite.git/commitdiff
Use finer asserts from unittest
authorFrédéric Perrin <fred@fperrin.net>
Sun, 9 Oct 2016 23:21:17 +0000 (00:21 +0100)
committerFrédéric Perrin <fred@fperrin.net>
Sun, 9 Oct 2016 23:21:17 +0000 (00:21 +0100)
quotes/tests.py

index 772d4e3491d90f143de4b1cdab5d22107dd81c32..fe7e0a80456ac99edd9adbe959ecb4dce352e7a5 100644 (file)
@@ -40,18 +40,19 @@ class ViewsTest(TestCase):
         a2 = Author.objects.create(name="Author without notes")
         w2 = Work.objects.create(name="Work without notes", author=a2)
         q2 = Quote.objects.create(text="Quote02, no tags", work=w2)
+        self.assertSequenceEqual(q2.tags.all(), [])
 
     def test_all(self):
         content = self.getPage('all/')
         for a in Author.objects.all():
-            self.assertTrue(a.name in content, msg=content)
-            self.assertTrue(a.notes in content, msg=content)
+            self.assertIn(a.name, content)
+            self.assertIn(a.notes, content)
         for w in Work.objects.all():
-            self.assertTrue(w.name in content)
-            self.assertTrue(w.notes in content, content)
+            self.assertIn(w.name, content)
+            self.assertIn(w.notes, content)
         for q in Quote.objects.all():
-            self.assertTrue(q.text in content, content)
-            self.assertTrue(q.notes in content, content)
+            self.assertIn(q.text, content)
+            self.assertIn(q.notes, content)
 
     def test_random(self):
         seen = {}
@@ -76,26 +77,36 @@ class ViewsTest(TestCase):
         self.assertEqual(q.count(), 1)
         q = q[0]
 
-        # check the individual quote page
+        # check the individual quote page; each of the note type is displayed
         quotepage = self.getPage('show/%s/' % q.id)
-        self.assertTrue(q.text in quotepage)
-        self.assertTrue("author_notes" in quotepage)
+        self.assertIn(q.text, quotepage)
+        self.assertIn("author_notes", quotepage)
+        self.assertIn("work_notes", quotepage)
+        self.assertIn("tag_link", quotepage)
         self.assertEqual(quotepage.count("tag_link"), 2)
 
-        # check the work page
+        # check the work page; each of the note type is displayed, and
+        # the work notes are shown only once
         workpage = self.getPage('work/%s/' % q.work.id)
-        self.assertTrue(q.text in workpage)
-        self.assertTrue("work_notes" in workpage)
-        
-        # check the author page
+        self.assertIn(q.text, workpage)
+        self.assertIn("author_notes", workpage)
+        self.assertIn("work_notes", workpage)
+        self.assertEqual(workpage.count("work_notes"), 1)
+        self.assertIn("tag_link", workpage)
+
+        # check the author page; each of the note type is displayed, and
+        # the author notes are shown only once
         authorpage = self.getPage('author/%s/' % q.work.author.id)
-        self.assertTrue(q.text in authorpage)
-        self.assertTrue("author_notes" in authorpage)
+        self.assertIn(q.text, authorpage)
+        self.assertIn("author_notes", authorpage)
+        self.assertEqual(authorpage.count("author_notes"), 1)
+        self.assertIn("work_notes", authorpage)
+        self.assertIn("tag_link", authorpage)
 
         # check the tag page
         for tag in q.tags.all():
             tagpage = self.getPage('tag/%s/' % tag.id)
-            self.assertTrue(q.text in tagpage)
+            self.assertIn(q.text, tagpage)
 
     def test_views_minimal_data(self):
         q = Quote.objects.filter(text__startswith="Quote02")
@@ -103,14 +114,23 @@ class ViewsTest(TestCase):
         q = q[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)
+        self.assertIn(q.text, quotepage)
+        self.assertNotIn("author_notes", quotepage)
+        self.assertNotIn("work_notes", quotepage)
+        self.assertNotIn("tag_link", quotepage)
+
+        workpage = self.getPage('work/%s/' % q.work.id)
+        self.assertIn(q.text, workpage)
+        self.assertNotIn("author_notes", quotepage)
+        self.assertNotIn("work_notes", quotepage)
+        self.assertNotIn("tag_link", quotepage)
 
         authorpage = self.getPage('author/%s/' % q.work.author.id)
-        self.assertTrue(q.text in authorpage)
-        self.assertFalse("author_notes" in authorpage)
-        self.assertFalse('Quote01, two tags' in authorpage)        
+        self.assertIn(q.text, authorpage)
+        self.assertNotIn("author_notes", authorpage)
+        self.assertNotIn("work_notes", authorpage)
+        self.assertNotIn("tag_link", authorpage)
+        self.assertNotIn('Quote01, two tags', authorpage)
 
     def test_view_author_notes_once(self):
         # check that on the per-author view, the author notes aren't display