Skip to content

Commit 5d59ad3

Browse files
committed
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
Mostly taken from patch by John Kristensen (jerrykan). Tests for python3 and 2 created for minimal and jinja2 templates. Removed FIXME for special case config settings for jinja and responsive templates. config_ini.ini mechanism makes it obsolete. Demo removes config_ini.ini file in home directory. Also remove encoding of utf-8 from initial_data.py to remove SyntaxError: encoding declaration in Unicode string under python2.
1 parent f113bba commit 5d59ad3

File tree

4 files changed

+91
-12
lines changed

4 files changed

+91
-12
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ Fixed:
5252
the data per rfc7232. Properly validate any form of ETag suffixed or
5353
non-suffixed for If-Match.
5454
- issue2551178 - fix Traceback in Apache WSGI - during file upload
55+
- issue2551179 - make roundup-demo initialize templates using
56+
config_ini.ini overrides. Needed for jinja to set template lang etc.
57+
Recognize minimal template when presented with a full
58+
path. (John Kristensen (jerrykan) and John Rouillard)
5559

5660
Features:
5761

roundup/demo.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ def install_demo(home, backend, template):
3939
from roundup import init, instance, password
4040

4141
# set up the config for this tracker
42-
config = configuration.CoreConfig()
42+
template_dir = os.path.join('share', 'roundup', 'templates', template)
43+
44+
# Load optional override ini file. Missing ini file is ignored.
45+
template_cfg = configuration.UserConfig(template_dir + "/config_ini.ini")
46+
config = configuration.CoreConfig(settings={
47+
i.name: i.get() for i in template_cfg.items()
48+
})
4349
config['TRACKER_HOME'] = home
4450
config['MAIL_DOMAIN'] = 'localhost'
4551
config['DATABASE'] = 'db'
@@ -64,8 +70,18 @@ def install_demo(home, backend, template):
6470
print(" %s" % home)
6571
sys.exit(1)
6672

67-
template_dir = os.path.join('share', 'roundup', 'templates', template)
6873
init.install(home, template_dir)
74+
# Remove config_ini.ini file from tracker_home (not template dir).
75+
# Ignore file not found - not all templates have
76+
# config_ini.ini files.
77+
try:
78+
os.remove(home + "/config_ini.ini")
79+
except OSError as e: # FileNotFound exception under py3
80+
if e.errno == 2:
81+
pass
82+
else:
83+
raise
84+
6985
# don't have email flying around
7086
nosyreaction = os.path.join(home, 'detectors', 'nosyreaction.py')
7187
if os.path.exists(nosyreaction):
@@ -97,12 +113,6 @@ def install_demo(home, backend, template):
97113

98114
# write the config
99115
config['INSTANT_REGISTRATION'] = 1
100-
# FIXME: Move template-specific demo initialization into the templates.
101-
if template == 'responsive':
102-
config['STATIC_FILES'] = "static"
103-
if template == 'jinja2':
104-
config['TEMPLATE_ENGINE'] = 'jinja2'
105-
config['STATIC_FILES'] = "static"
106116
config.save(os.path.join(home, config.INI_FILE))
107117

108118
# open the tracker and initialise
@@ -113,7 +123,7 @@ def install_demo(home, backend, template):
113123
db = tracker.open('admin')
114124
# FIXME: Move tracker-specific demo initialization into the tracker
115125
# templates.
116-
if template == 'minimal':
126+
if os.path.basename(template) == 'minimal':
117127
db.user.create(username='demo', password=password.Password('demo'),
118128
roles='User')
119129
else:

share/roundup/templates/jinja2/initial_data.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
31
from roundup import password, date
42

53
pri = db.getclass('priority')

test/test_demo.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def tearDown(self):
3333
except FileNotFoundError:
3434
pass
3535

36-
def testDemo(self):
36+
def testDemoClassic(self):
3737
with captured_output() as (out, err):
3838
install_demo(self.home, 'anydbm', 'classic')
3939
output = out.getvalue().strip()
@@ -61,4 +61,71 @@ def test_get_server(self):
6161
# last line in the output.
6262
self.assertIn("Keyboard Interrupt: exiting", output.split('\n'))
6363

64+
def testDemoMinimal(self):
65+
with captured_output() as (out, err):
66+
# use a modified path that resolves when
67+
install_demo(self.home, 'sqlite', '../templates/minimal')
68+
output = out.getvalue().strip()
69+
print(output)
70+
71+
# verify that db was set properly by reading config
72+
with open(self.home + "/config.ini", "r") as f:
73+
config_lines = f.readlines()
74+
75+
self.assertIn("backend = sqlite\n", config_lines)
76+
77+
# dummy up the return of get_server so the serve_forever method
78+
# raises keyboard interrupt exiting the server so the test exits.
79+
gs = roundup.scripts.roundup_server.ServerConfig.get_server
80+
def raise_KeyboardInterrupt():
81+
raise KeyboardInterrupt
82+
83+
def test_get_server(self):
84+
httpd = gs(self)
85+
httpd.serve_forever = raise_KeyboardInterrupt
86+
return httpd
87+
88+
roundup.scripts.roundup_server.ServerConfig.get_server = test_get_server
89+
90+
# Run under context manager to capture output of startup text.
91+
with captured_output() as (out, err):
92+
run_demo(self.home)
93+
output = out.getvalue().strip()
94+
print(output)
95+
# if the server installed and started this will be the
96+
# last line in the output.
97+
self.assertIn("Keyboard Interrupt: exiting", output.split('\n'))
6498

99+
def testDemoJinja(self):
100+
with captured_output() as (out, err):
101+
install_demo(self.home, 'anydbm', 'jinja2')
102+
output = out.getvalue().strip()
103+
print(output)
104+
105+
# verify that template was set to jinja2 by reading config
106+
with open(self.home + "/config.ini", "r") as f:
107+
config_lines = f.readlines()
108+
109+
self.assertIn("template_engine = jinja2\n", config_lines)
110+
111+
# dummy up the return of get_server so the serve_forever method
112+
# raises keyboard interrupt exiting the server so the test exits.
113+
gs = roundup.scripts.roundup_server.ServerConfig.get_server
114+
def raise_KeyboardInterrupt():
115+
raise KeyboardInterrupt
116+
117+
def test_get_server(self):
118+
httpd = gs(self)
119+
httpd.serve_forever = raise_KeyboardInterrupt
120+
return httpd
121+
122+
roundup.scripts.roundup_server.ServerConfig.get_server = test_get_server
123+
124+
# Run under context manager to capture output of startup text.
125+
with captured_output() as (out, err):
126+
run_demo(self.home)
127+
output = out.getvalue().strip()
128+
print(output)
129+
# if the server installed and started this will be the
130+
# last line in the output.
131+
self.assertIn("Keyboard Interrupt: exiting", output.split('\n'))

0 commit comments

Comments
 (0)