]> gitweb.fperrin.net Git - djsite.git/blobdiff - quotes/tests.py
Add a 'work' concept
[djsite.git] / quotes / tests.py
index 00237fa2ec9fdfc4e30e66309f6400354cec74f4..3836f4e5e829dce28360b52e25235f0b2215dc40 100644 (file)
@@ -2,19 +2,19 @@ import sys
 from django.test import TestCase, Client
 
 # Create your tests here.
-from .models import Author, Tag, Quote
+from .models import Tag, Author, Work, Quote
 
 class QuoteTest(TestCase):
     def setUp(self):
         a1 = Author.objects.create(name="JFK")
-        q1 = Quote.objects.create(text="Ich bin...", author=a1)
+        w1 = Work.objects.create(name="Berlin speech", author=a1)
+        q1 = Quote.objects.create(text="Ich bin...", work=w1)
 
     def test_one(self):
         q = Quote.objects.filter(text__startswith="Ich")
         self.assertEqual(q.count(), 1)
         q = q[0]
-        self.assertEqual(q.author.name, "JFK")
-
+        self.assertEqual(q.work.author.name, "JFK")
 
 class ViewsTest(TestCase):
     def getPage(self, url, exp_status=200):
@@ -26,21 +26,32 @@ class ViewsTest(TestCase):
 
     def setUp(self):
         a1 = Author.objects.create(name="Author with notes",
-                                   notes="Some notes")
+                                   notes="Some notes for the author")
+        w1 = Work.objects.create(name="Context with some notes",
+                                 author=a1,
+                                 notes="Some notes for the work")
+        q1 = Quote.objects.create(text="Quote01, two tags",
+                                  work=w1,
+                                  notes="Some notes for the quote")
         t1 = Tag.objects.create(tag="tag01-1")
         t2 = Tag.objects.create(tag="tag01-2")
-        q1 = Quote.objects.create(text="Quote01, two tags", author=a1)
         q1.tags.add(t1, t2)
 
         a2 = Author.objects.create(name="Author without notes")
-        q2= Quote.objects.create(text="Quote02, no tags", author=a2)
+        w2 = Work.objects.create(name="Work without notes", author=a2)
+        q2 = Quote.objects.create(text="Quote02, no tags", work=w2)
 
     def test_all(self):
         content = self.getPage('all/')
         for a in Author.objects.all():
-            self.assertTrue(a.name in content)
+            self.assertTrue(a.name in content, msg=content)
+            self.assertTrue(a.notes in content, msg=content)
+        for w in Work.objects.all():
+            self.assertTrue(w.name in content)
+            self.assertTrue(w.notes in content, content)
         for q in Quote.objects.all():
-            self.assertTrue(q.text in content)
+            self.assertTrue(q.text in content, content)
+            self.assertTrue(q.notes in content, content)
 
     def test_views_all_data(self):
         q = Quote.objects.filter(text__startswith="Quote01")
@@ -53,8 +64,13 @@ class ViewsTest(TestCase):
         self.assertTrue("author_notes" in quotepage)
         self.assertEqual(quotepage.count("tag_link"), 2)
 
+        # check the work page
+        workpage = self.getPage('work/%s/' % q.work.id)
+        self.assertTrue(q.text in workpage)
+        self.assertTrue("work_notes" in workpage)
+        
         # check the author page
-        authorpage = self.getPage('author/%s/' % q.author.id)
+        authorpage = self.getPage('author/%s/' % q.work.author.id)
         self.assertTrue(q.text in authorpage)
         self.assertTrue("author_notes" in authorpage)
 
@@ -73,7 +89,7 @@ class ViewsTest(TestCase):
         self.assertFalse("author_notes" in quotepage)
         self.assertEqual(quotepage.count("tag_link"), 0)
 
-        authorpage = self.getPage('author/%s/' % q.author.id)
+        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)        
@@ -86,4 +102,4 @@ class ViewsTest(TestCase):
         a = a[0]
 
         authorpage = self.getPage('author/%s/' % a.id)
-        self.assertEqual(authorpage.count("Some notes"), 1)
+        self.assertEqual(authorpage.count("Some notes for the author"), 1)