Increased specificity of penfield get_article conditions for 404 raising. Corrected...
[philo.git] / tests.py
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
6
7
8 class NodeURLTestCase(TestCase):
9         """Tests the features of the node_url template tag."""
10         urls = 'philo.urls'
11         fixtures = ['test_fixtures.json']
12         
13         def setUp(self):
14                 if 'south' in settings.INSTALLED_APPS:
15                         from south.management.commands.migrate import Command
16                         command = Command()
17                         command.handle(all_apps=True)
18                 
19                 self.templates = [template.Template(string) for string in
20                         [
21                                 "{% node_url %}", # 0
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
32                         ]
33                 ]
34                 
35                 nodes = Node.objects.all()
36                 blog = Blog.objects.all()[0]
37                 
38                 self.context = template.Context({
39                         'node': nodes[0],
40                         'node2': nodes[1],
41                         'nodes': nodes,
42                         'entry': BlogEntry.objects.all()[0],
43                         'tag': blog.entry_tags.all()[0],
44                         'date': blog.entry_dates['day'][0]
45                 })
46         
47         def test_nodeurl(self):
48                 for i, template in enumerate(self.templates):
49                         t = template.render(self.context)
50                         
51                         if i == 0:
52                                 self.assertEqual(t, "/root/never/")
53                         elif i == 1:
54                                 self.assertEqual(t, "/root/blog/")
55                         elif i == 2:
56                                 self.assertEqual(t, "<p>root/never/</p>")
57                         elif i == 3:
58                                 self.assertEqual(t, "/root/never/")
59                         elif i == 4:
60                                 self.assertEqual(t, settings.TEMPLATE_STRING_IF_INVALID)
61                         elif i == 5:
62                                 self.assertEqual(t, "/root/blog/2010/10/20/first-entry")
63                         elif i == 6:
64                                 self.assertEqual(t, "/root/blog/tags/test-tag/")
65                         elif i == 7:
66                                 self.assertEqual(t, "/root/blog/2010/10/20")
67                         elif i == 8:
68                                 self.assertEqual(t, "<em>/ROOT/BLOG/2010/10/20</em>")
69                         elif i == 9:
70                                 self.assertEqual(t, "/root/blog/2010/10")
71                         elif i == 10:
72                                 self.assertEqual(t, "/root/blog/2010/")
73                         else:
74                                 print "Rendered as:\n%s\n\n" % t