comparison test/test_demo.py @ 7704:5b1163dca9e1

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.
author John Rouillard <rouilj@ieee.org>
date Mon, 20 Nov 2023 21:59:40 -0500
parents 859c57bc8d91
children 5b47966bf6f0
comparison
equal deleted inserted replaced
7703:69e6bcb39f90 7704:5b1163dca9e1
82 # if the server installed and started this will be the 82 # if the server installed and started this will be the
83 # last line in the output. 83 # last line in the output.
84 self.assertIn("Keyboard Interrupt: exiting", output.split('\n')) 84 self.assertIn("Keyboard Interrupt: exiting", output.split('\n'))
85 85
86 def testDemoClassic(self): 86 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)
88 108
89 def testDemoMinimal(self): 109 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)
91 133
92 @skip_jinja2 134 @skip_jinja2
93 def testDemoJinja(self): 135 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)
95 144
96 # verify that template was set to jinja2 by reading config 145 # verify that template was set to jinja2 by reading config
97 with open(self.home + "/config.ini", "r") as f: 146 with open(self.home + "/config.ini", "r") as f:
98 config_lines = f.read() 147 config_lines = f.read()
99 148

Roundup Issue Tracker: http://roundup-tracker.org/