From: Frédéric Perrin Date: Wed, 28 Sep 2016 22:34:06 +0000 (+0100) Subject: Add first UT X-Git-Url: http://gitweb.fperrin.net/?p=djsite.git;a=commitdiff_plain;h=af3f857eea25b939f927832741f377e4de401f9c Add first UT --- diff --git a/quotes/templates/quotes/display.html b/quotes/templates/quotes/display.html index 7873c81..1369e2c 100644 --- a/quotes/templates/quotes/display.html +++ b/quotes/templates/quotes/display.html @@ -13,7 +13,9 @@

Tags: {% for tag in quote.tags.all %} - {{ tag.tag }} + + {{ tag.tag }} + {% endfor %}

{% endif %} diff --git a/quotes/tests.py b/quotes/tests.py index 7ce503c..556e925 100644 --- a/quotes/tests.py +++ b/quotes/tests.py @@ -1,3 +1,68 @@ -from django.test import TestCase +import sys +from django.test import TestCase, Client # Create your tests here. +from .models import Author, Tag, Quote + +class QuoteTest(TestCase): + def setUp(self): + a1 = Author.objects.create(name="JFK") + q1 = Quote.objects.create(text="Ich bin...", author=a1) + + 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") + + +class ViewsTest(TestCase): + def setUp(self): + a1 = Author.objects.create(name="Author with notes", + notes="Some notes") + 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) + + 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) + + 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) + + 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) + + 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) + + 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)