Skip to content

Commit 33c9b61

Browse files
committed
test: actually test output from running demo server code
I was invoking demo mode, but not testing the output to verify it was making it to the point where it would start the server. Check that an expected database file was created to verify that the db setting was honored. Also test TEMPLATE-INFO.txt to verify that the correct template was being instantiated. Tested under 3.13 as wel using docker command line (wrapped): docker run -it -u 1000 --rm -v $PWD:/usr/src/myapp -w /usr/src/myapp python:3.13.0a1-alpine3.18 sh -c 'export HOME=/tmp/home; mkdir $HOME; python -m pip install pytest pytest-env requests jinja2; python -m pytest -v test/test_demo.py' If demo mode tries to start as root, it exits with an error, so it must be run with -u uid.
1 parent 5cd5a93 commit 33c9b61

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

test/test_demo.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,63 @@ def test_get_server(self):
8484
self.assertIn("Keyboard Interrupt: exiting", output.split('\n'))
8585

8686
def testDemoClassic(self):
87-
self.run_install_demo("classic")
87+
with captured_output() as (out, err):
88+
self.run_install_demo("classic")
89+
self.assertIn("http://localhost:8917/demo/", out.getvalue())
90+
91+
# verify the default anydbm db is created
92+
db_file = self.home + "/db/nodes.user"
93+
self.assertTrue(os.path.isfile(db_file),
94+
"expected db file %s does not exist" % db_file)
95+
96+
# verify requested template was used
97+
with open(self.home + "/TEMPLATE-INFO.txt", "r") as f:
98+
info_lines = f.read()
99+
100+
try:
101+
# handle text files with \r\n line endings
102+
info_lines.index("\r", 0, 100)
103+
info_lines = info_lines.replace("\r\n", "\n")
104+
except ValueError:
105+
pass
106+
107+
self.assertIn("Name: classic-_test_demo\n", info_lines)
88108

89109
def testDemoMinimal(self):
90-
self.run_install_demo('../templates/minimal', db="sqlite")
110+
# test explicit path to template as others test template
111+
# search path.
112+
with captured_output() as (out, err):
113+
self.run_install_demo('../templates/minimal', db="sqlite")
114+
self.assertIn("http://localhost:8917/demo/", out.getvalue())
115+
116+
# verify the requested sqlite db file is created
117+
db_file = self.home + "/db/db"
118+
self.assertTrue(os.path.isfile(db_file),
119+
"expected db file %s does not exist" % db_file)
120+
121+
# verify requested template was used
122+
with open(self.home + "/TEMPLATE-INFO.txt", "r") as f:
123+
info_lines = f.read()
124+
125+
try:
126+
# handle text files with \r\n line endings
127+
info_lines.index("\r", 0, 100)
128+
info_lines = info_lines.replace("\r\n", "\n")
129+
except ValueError:
130+
pass
131+
132+
self.assertIn("Name: minimal-_test_demo\n", info_lines)
91133

92134
@skip_jinja2
93135
def testDemoJinja(self):
94-
self.run_install_demo('jinja2', db="anydbm")
136+
with captured_output() as (out, err):
137+
self.run_install_demo('jinja2', db="anydbm")
138+
self.assertIn("http://localhost:8917/demo/", out.getvalue())
139+
140+
# verify the requested anydbm db file is created
141+
db_file = self.home + "/db/nodes.user"
142+
self.assertTrue(os.path.isfile(db_file),
143+
"expected db file %s does not exist" % db_file)
95144

96145
# verify that template was set to jinja2 by reading config
97146
with open(self.home + "/config.ini", "r") as f:

0 commit comments

Comments
 (0)