forked from django-cms/django-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testserver.py
182 lines (156 loc) · 5.03 KB
/
testserver.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/env python
import os
import sys
def noop_gettext(s):
return s
permission = True
cms_toolbar_edit_on = 'edit'
port = 8000
for arg in sys.argv:
if arg == '--CMS_PERMISSION=False':
permission = False
if arg == '--CMS_TOOLBAR_URL__EDIT_ON=test-edit':
cms_toolbar_edit_on = 'test-edit'
if arg.startswith('--port='):
port = arg.split('=')[1]
gettext = noop_gettext
class DisableMigrations:
def __contains__(self, item):
return True
def __getitem__(self, item):
return 'notmigrations'
def update(self, whatever):
return True
HELPER_SETTINGS = dict(
ALLOWED_HOSTS=[u'0.0.0.0', u'localhost'],
CMS_PERMISSION=permission,
LANGUAGES=(
('en', u'English'),
('de', u'Deutsch'),
('it', u'Italiano'),
('zh-cn', u'Chinese (Simplified)'),
),
LANGUAGE_CODE='en',
PARLER_LANGUAGES={
1: (
{'code': 'en', 'fallbacks': ['de',]},
{'code': 'de', 'fallbacks': ['en',]},
{'code': 'it', 'fallbacks': ['en',]},
{'code': 'zh-cn', 'fallbacks': ['en',]},
),
'default': {
'fallback': 'en',
'hide_untranslated': False,
},
},
PARLER_ENABLE_CACHING=False,
CMS_CACHE_DURATIONS={
'menus': 0,
'content': 0,
'permissions': 0,
},
CMS_PAGE_CACHE=False,
CMS_TOOLBAR_URL__EDIT_ON=cms_toolbar_edit_on,
# required for integration tests
LOGIN_URL='/admin/login/?user-login=test',
CMS_LANGUAGES={
1: [
{
'code': 'en',
'name': gettext('English'),
'fallbacks': ['de',],
},
{
'code': 'de',
'name': gettext('German'),
'fallbacks': ['en',],
},
{
'code': 'it',
'name': gettext('Italian'),
'fallbacks': ['en',],
},
{
'code': 'zh-cn',
'name': gettext('Chinese Simplified'),
'fallbacks': ['en',]
},
],
'default': {
'fallbacks': ['en', 'de',],
'redirect_on_fallback': False,
'public': True,
'hide_untranslated': False,
}
},
CMS_PLACEHOLDER_CONF={
'placeholder_content_2': {
'plugin_modules': {
'Bootstrap3ButtonCMSPlugin': 'Different Grouper'
},
'plugin_labels': {
'Bootstrap3ButtonCMSPlugin': gettext('Add a link')
},
}
},
INSTALLED_APPS=[
'djangocms_text_ckeditor',
'cms.test_utils.project.pluginapp.plugins.link',
'cms.test_utils.project.pluginapp.plugins.multicolumn',
'cms.test_utils.project.pluginapp.plugins.multiwrap',
'cms.test_utils.project.pluginapp.plugins.style',
'cms.test_utils.project.pluginapp.plugins.dynamic_js_loading',
'cms.test_utils.project.placeholderapp',
],
MIDDLEWARE=[
'cms.middleware.utils.ApphookReloadMiddleware',
'django.middleware.http.ConditionalGetMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'cms.middleware.language.LanguageCookieMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
],
TEMPLATE_DIRS=(
os.path.join(
os.path.dirname(__file__),
'cms', 'test_utils', 'project', 'templates', 'integration'),
),
CMS_TEMPLATES=(
('fullwidth.html', 'Fullwidth'),
('page.html', 'Standard page'),
('simple.html', 'Simple page'),
),
MIGRATION_MODULES={
'auth': None,
'admin': None,
'contenttypes': None,
'sessions': None,
'sites': None,
'cms': None,
'menus': None,
'djangocms_text_ckeditor': None,
},
)
def _helper_patch(*args, **kwargs):
from django.core.management import call_command
from app_helper import utils
call_command('migrate', run_syncdb=True)
utils.create_user('normal', '[email protected]', 'normal', is_staff=True, base_cms_permissions=True,
permissions=['view_page'])
def run():
from app_helper import runner
from app_helper import utils
os.environ.setdefault('DATABASE_URL', 'sqlite://localhost/testdb.sqlite')
# Patch app_helper to create tables
utils._create_db = _helper_patch
# we use '.runner()', not '.cms()' nor '.run()' because it does not
# add 'test' argument implicitly
runner.runner([sys.argv[0], 'cms', '--cms', 'server', '--bind', '0.0.0.0', '--port', str(port)])
if __name__ == "__main__":
run()