]> gitweb.fperrin.net Git - djsite.git/commitdiff
Add first UT
authorFrédéric Perrin <fred@fperrin.net>
Wed, 28 Sep 2016 22:34:06 +0000 (23:34 +0100)
committerFrédéric Perrin <fred@fperrin.net>
Wed, 28 Sep 2016 22:34:06 +0000 (23:34 +0100)
quotes/templates/quotes/display.html
quotes/tests.py

index 7873c81aadf98e6ef18e95f8f9652ca6797d2522..1369e2ce96f2ac30abb2d9388aa564f587fe66cc 100644 (file)
@@ -13,7 +13,9 @@
     <p class="tags">
       Tags:
       {% for tag in quote.tags.all %}
-        <a href="{% url 'quotes:tags' tag.id %}">{{ tag.tag }}</a>
+       <a href="{% url 'quotes:tags' tag.id %}" class="tag_link">
+         {{ tag.tag }}
+       </a>
       {% endfor %}
     </p>
   {% endif %}
index 7ce503c2dd97ba78597f6ff6e4393132753573f6..556e9252c3377477911b077da4e64315b8f067b9 100644 (file)
@@ -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)