a45f47c7b5dbf7b4db46863ae5313c179244952f
[django-ssify.git] / tests / tests / test_args.py
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.
4 #
5 from __future__ import unicode_literals
6
7 import re
8 from django.test import TestCase
9 from django.test.utils import override_settings
10 from tests.tests_utils import split_ssi
11
12
13 class ArgsTestCase(TestCase):
14     def test_args(self):
15         self.assertEqual(
16             sorted(split_ssi(self.client.get('/args').content)),
17             sorted([b"<!--#set var='vff80027f1d552d08d46c8b603948d85c' value='2'-->",
18                  b"<!--#set var='veeb5ec4364971b409c48e36bd1428d03' value='1'-->",
19                  b"<!--#set var='v05a1f9ec205c5aa84197f6b326c518a2' value='0'-->",
20                  b"<!--#echo var='v05a1f9ec205c5aa84197f6b326c518a2' encoding='none'-->",
21                  ])
22             )
23
24     def test_args_included(self):
25         self.assertEqual(
26             self.client.get('/args/3').content.strip(),
27             b"<!--#echo var='v05a1f9ec205c5aa84197f6b326c518a2' encoding='none'-->"
28             )
29
30     def test_include_args(self):
31         self.assertEqual(
32             sorted(split_ssi(self.client.get('/include_args').content)),
33             sorted([b"<!--#set var='vf6aba0780227af845107c046f336cc8a' value='3'-->",
34                  b"<!--#set var='vff80027f1d552d08d46c8b603948d85c' value='2'-->",
35                  b"<!--#set var='veeb5ec4364971b409c48e36bd1428d03' value='1'-->",
36                  b"<!--#set var='v05a1f9ec205c5aa84197f6b326c518a2' value='0'-->",
37                  b"<!--#include file='/args/${vf6aba0780227af845107c046f336cc8a}'-->",
38                  ]),
39             )
40
41         # Test a second time, this time from cache.
42         self.assertEqual(
43             sorted(split_ssi(self.client.get('/include_args').content)),
44             sorted([b"<!--#set var='vf6aba0780227af845107c046f336cc8a' value='3'-->",
45                  b"<!--#set var='vff80027f1d552d08d46c8b603948d85c' value='2'-->",
46                  b"<!--#set var='veeb5ec4364971b409c48e36bd1428d03' value='1'-->",
47                  b"<!--#set var='v05a1f9ec205c5aa84197f6b326c518a2' value='0'-->",
48                  b"<!--#include file='/args/${vf6aba0780227af845107c046f336cc8a}'-->",
49                  ]),
50             )
51
52     @override_settings(SSIFY_DEBUG=True)
53     def test_debug_render_include_args(self):
54         pass
55         """Renders the complete view using the DebugSsiMiddleware."""
56         response = self.client.get('/include_args')
57         if hasattr(response, 'render') and callable(response.render):
58             response.render()
59         self.assertEqual(
60             response.content.strip(),
61             b"""0"""
62         )