1 # -*- coding: utf-8 -*-
2 # This file is part of django-ssify, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See README.md for more information.
5 from __future__ import unicode_literals
9 from django.test import TestCase
10 from django.test.utils import override_settings
11 from ssify.exceptions import UndeclaredSsiVarsError, UnusedSsiVarsWarning
12 from tests.tests_utils import split_ssi
15 class BasicTestCase(TestCase):
18 self.client.get('/number_zero').content.strip(),
19 b"<!--#set var='ve023a08d2c2075118e25b5f4339438dc' value='0'-->\n"
20 b"<!--#echo var='ve023a08d2c2075118e25b5f4339438dc' "
24 def test_basic_include(self):
26 self.client.get('/basic_include').content.strip(),
27 b"<!--#include file='/language/pl'-->"
30 def test_single_quote(self):
32 self.client.get('/quote/3').content.strip(),
33 b"""Explicit is better than implicit.
34 Line 3 of <!--#echo var='va50d914691ecf9b421c680d93ba1263e' encoding='none'-->
35 <!--#if expr='${vddc386e120ab274a980ab67384391a1a}'-->Odd number of characters.
36 <!--#else-->Even number of characters.
40 def test_undeclared_vars(self):
41 self.assertRaises(UndeclaredSsiVarsError,
43 '/quote_undeclared/3')
45 def test_overdeclared_vars(self):
46 with warnings.catch_warnings(record=True) as w:
47 response = self.client.get('/quote_overdeclared/3')
48 self.assertIs(w[-1].category, UnusedSsiVarsWarning)
50 def test_random_quote(self):
52 sorted(split_ssi(self.client.get('/').content)),
53 sorted([b"<!--#set var='va50d914691ecf9b421c680d93ba1263e' value='22'-->",
54 b"<!--#set var='v3e7f638af74c9f420b6d2c5fe4dda51d' value='4'-->",
55 b"<!--#set var='vafe010f2e683908fee32c48d01bb2650' value=''-->",
56 b"<!--#include file='/random_quote'-->"])
59 # Do it again, this time from cache.
61 sorted(split_ssi(self.client.get('/').content)),
62 sorted([b"<!--#set var='va50d914691ecf9b421c680d93ba1263e' value='22'-->",
63 b"<!--#set var='v3e7f638af74c9f420b6d2c5fe4dda51d' value='4'-->",
64 b"<!--#set var='vafe010f2e683908fee32c48d01bb2650' value=''-->",
65 b"<!--#include file='/random_quote'-->"])
68 self.client.get('/random_quote').content.strip(),
70 b"file='/quote/${v3e7f638af74c9f420b6d2c5fe4dda51d}'-->"
73 @override_settings(SSIFY_DEBUG=True)
74 def test_debug_render_random_quote(self):
75 """Renders the complete view using the DebugSsiMiddleware."""
76 response = self.client.get('/')
77 if hasattr(response, 'render') and callable(response.render):
80 response.content.strip(),
81 b"""Simple is better than complex.
83 Even number of characters."""