1 from django.test import TestCase
2 from django import template
3 from django.conf import settings
4 from philo.models import Node, Page, Template
5 from philo.contrib.penfield.models import Blog, BlogView, BlogEntry
8 class NodeURLTestCase(TestCase):
9 """Tests the features of the node_url template tag."""
11 fixtures = ['test_fixtures.json']
14 if 'south' in settings.INSTALLED_APPS:
15 from south.management.commands.migrate import Command
17 command.handle(all_apps=True)
19 self.templates = [template.Template(string) for string in
22 "{% node_url for node2 %}", # 1
23 "{% node_url as hello %}<p>{{ hello|slice:'1:' }}</p>", # 2
24 "{% node_url for nodes|first %}", # 3
25 "{% node_url with entry %}", # 4
26 "{% node_url with entry for node2 %}", # 5
27 "{% node_url with tag for node2 %}", # 6
28 "{% node_url with date for node2 %}", # 7
29 "{% node_url entries_by_day year=date|date:'Y' month=date|date:'m' day=date|date:'d' for node2 as goodbye %}<em>{{ goodbye|upper }}</em>", # 8
30 "{% node_url entries_by_month year=date|date:'Y' month=date|date:'m' for node2 %}", # 9
31 "{% node_url entries_by_year year=date|date:'Y' for node2 %}", # 10
35 nodes = Node.objects.all()
36 blog = Blog.objects.all()[0]
38 self.context = template.Context({
42 'entry': BlogEntry.objects.all()[0],
43 'tag': blog.entry_tags.all()[0],
44 'date': blog.entry_dates['day'][0]
47 def test_nodeurl(self):
48 for i, template in enumerate(self.templates):
49 t = template.render(self.context)
52 self.assertEqual(t, "/root/never/")
54 self.assertEqual(t, "/root/blog/")
56 self.assertEqual(t, "<p>root/never/</p>")
58 self.assertEqual(t, "/root/never/")
60 self.assertEqual(t, settings.TEMPLATE_STRING_IF_INVALID)
62 self.assertEqual(t, "/root/blog/2010/10/20/first-entry")
64 self.assertEqual(t, "/root/blog/tags/test-tag/")
66 self.assertEqual(t, "/root/blog/2010/10/20")
68 self.assertEqual(t, "<em>/ROOT/BLOG/2010/10/20</em>")
70 self.assertEqual(t, "/root/blog/2010/10")
72 self.assertEqual(t, "/root/blog/2010/")
74 print "Rendered as:\n%s\n\n" % t