-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
71 lines (51 loc) · 1.73 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding:utf-8 -*-
'''
@author: wTayyeb https://github.com/wtayyeb
@license: MIT
'''
import django
from django.http.response import HttpResponseRedirect
from django.test import TestCase
from django.test.client import RequestFactory
from .middleware import ThemingMiddleware
from .models import ThemeManager
from .template import Loader
from .threadlocals import get_thread_variable
from .views import redirect_to_theme_fav_icon
try:
from django.template.engine import Engine
except ImportError:
Engine = None
class Test(TestCase):
@classmethod
def setUpClass(cls):
super(Test, cls).setUpClass()
cls.mgr = ThemeManager()
def test_find_themes(self):
themes = self.mgr.find_themes()
self.assertIn('default', themes)
self.assertIn('vecto', themes)
def test_choices(self):
choices = self.mgr.get_themes_choice()
ch_keys = list(ch[0] for ch in choices)
self.assertIn('default', ch_keys)
self.assertIn('vecto', ch_keys)
def test_middleware(self):
mw = ThemingMiddleware()
rf = RequestFactory()
request = rf.get('/')
mw.process_request(request)
sitetheme = get_thread_variable('sitetheme')
self.assertIsNone(sitetheme)
def test_template(self):
if django.VERSION >= (1, 8):
loader = Loader(Engine())
else:
loader = Loader()
res = list(loader.get_template_sources('base.html'))
self.assertGreaterEqual(len(res), 1)
cont = loader.load_template_source('base.html')
self.assertGreaterEqual(len(cont[0]), 10)
def test_view(self):
res = redirect_to_theme_fav_icon(None)
self.assertIsInstance(res, HttpResponseRedirect)