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")
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
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)