Mercurial > p > roundup > code
diff test/test_demo.py @ 6719:77eb1a41fc06
test cleanup. Make test method and convert tests to use.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 22 Jun 2022 16:18:46 -0400 |
| parents | 5a3a386aa8e7 |
| children | 4cfaddc2d53e |
line wrap: on
line diff
--- a/test/test_demo.py Wed Jun 22 15:38:25 2022 -0400 +++ b/test/test_demo.py Wed Jun 22 16:18:46 2022 -0400 @@ -33,12 +33,18 @@ except FileNotFoundError: pass - def testDemoClassic(self): + def run_install_demo(self, template, db="anydbm"): with captured_output() as (out, err): - install_demo(self.home, 'anydbm', 'classic') + install_demo(self.home, db, template) output = out.getvalue().strip() print(output) + # verify that db was set properly by reading config + with open(self.home + "/config.ini", "r") as f: + config_lines = f.readlines() + + self.assertIn("backend = %s\n"%db, config_lines) + # dummy up the return of get_server so the serve_forever method # raises keyboard interrupt exiting the server so the test exits. gs = roundup.scripts.roundup_server.ServerConfig.get_server @@ -61,46 +67,14 @@ # last line in the output. self.assertIn("Keyboard Interrupt: exiting", output.split('\n')) - def testDemoMinimal(self): - with captured_output() as (out, err): - # use a modified path that resolves when - install_demo(self.home, 'sqlite', '../templates/minimal') - output = out.getvalue().strip() - print(output) - - # verify that db was set properly by reading config - with open(self.home + "/config.ini", "r") as f: - config_lines = f.readlines() - - self.assertIn("backend = sqlite\n", config_lines) + def testDemoClassic(self): + self.run_install_demo("classic") - # dummy up the return of get_server so the serve_forever method - # raises keyboard interrupt exiting the server so the test exits. - gs = roundup.scripts.roundup_server.ServerConfig.get_server - def raise_KeyboardInterrupt(): - raise KeyboardInterrupt - - def test_get_server(self): - httpd = gs(self) - httpd.serve_forever = raise_KeyboardInterrupt - return httpd - - roundup.scripts.roundup_server.ServerConfig.get_server = test_get_server - - # Run under context manager to capture output of startup text. - with captured_output() as (out, err): - run_demo(self.home) - output = out.getvalue().strip() - print(output) - # if the server installed and started this will be the - # last line in the output. - self.assertIn("Keyboard Interrupt: exiting", output.split('\n')) + def testDemoMinimal(self): + self.run_install_demo('../templates/minimal', db="sqlite") def testDemoJinja(self): - with captured_output() as (out, err): - install_demo(self.home, 'anydbm', 'jinja2') - output = out.getvalue().strip() - print(output) + self.run_install_demo('jinja2', db="anydbm") # verify that template was set to jinja2 by reading config with open(self.home + "/config.ini", "r") as f: @@ -108,24 +82,3 @@ self.assertIn("template_engine = jinja2\n", config_lines) - # dummy up the return of get_server so the serve_forever method - # raises keyboard interrupt exiting the server so the test exits. - gs = roundup.scripts.roundup_server.ServerConfig.get_server - def raise_KeyboardInterrupt(): - raise KeyboardInterrupt - - def test_get_server(self): - httpd = gs(self) - httpd.serve_forever = raise_KeyboardInterrupt - return httpd - - roundup.scripts.roundup_server.ServerConfig.get_server = test_get_server - - # Run under context manager to capture output of startup text. - with captured_output() as (out, err): - run_demo(self.home) - output = out.getvalue().strip() - print(output) - # if the server installed and started this will be the - # last line in the output. - self.assertIn("Keyboard Interrupt: exiting", output.split('\n'))
