82751c7f56b00b0e7bfc1aee19d38be8313ad602
[django-ssify.git] / tests / tests.py
1 from django.test import Client, TestCase
2 from django.test.utils import override_settings
3
4
5 class SsifyTestCase(TestCase):
6     def setUp(self):
7         self.client = Client()
8
9     def test_zero(self):
10         self.assertEqual(
11             self.client.get('/number_zero').content,
12             "<!--#set var='ve023a08d2c2075118e25b5f4339438dc' value='0'-->"
13             "<!--#echo var='ve023a08d2c2075118e25b5f4339438dc' "
14             "encoding='none'-->"
15         )
16
17     def test_single_quote(self):
18         self.assertEqual(
19             self.client.get('/quote/3').content.strip(),
20             """Explicit is better than implicit.
21 Line 3 of <!--#echo var='va50d914691ecf9b421c680d93ba1263e' encoding='none'-->
22 <!--#if expr='${vddc386e120ab274a980ab67384391a1a}'-->Odd number of characters.
23 <!--#else-->Even number of characters.
24 <!--#endif-->"""
25         )
26
27     def test_random_quote(self):
28         self.assertEqual(
29             self.client.get('/').content.strip(),
30             "<!--#set var='vda0df841702ea993b36d101460264364' value='4'-->"
31             "<!--#set var='va50d914691ecf9b421c680d93ba1263e' value='22'-->"
32             "<!--#set var='vafe010f2e683908fee32c48d01bb2650' value=''-->"
33             "\n\n<!--#include file='/random_quote'-->"
34         )
35
36         # Do it again, this time from cache.
37         self.assertEqual(
38             self.client.get('/').content.strip(),
39             "<!--#set var='vda0df841702ea993b36d101460264364' value='4'-->"
40             "<!--#set var='va50d914691ecf9b421c680d93ba1263e' value='22'-->"
41             "<!--#set var='vafe010f2e683908fee32c48d01bb2650' value=''-->"
42             "\n\n<!--#include file='/random_quote'-->"
43         )
44         self.assertEqual(
45             self.client.get('/random_quote').content.strip(),
46             "<!--#include "
47             "file='/quote/${vda0df841702ea993b36d101460264364}'-->"
48         )
49
50     @override_settings(SSIFY_DEBUG=True)
51     def test_debug_render_random_quote(self):
52         """Renders the complete view using the DebugSsiMiddleware."""
53         response = self.client.get('/')
54         if hasattr(response, 'render') and callable(response.render):
55             response.render()
56         self.assertEqual(
57             response.content.strip(),
58             """Simple is better than complex.
59 Line 4 of 22
60 Even number of characters."""
61         )