comparison 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
comparison
equal deleted inserted replaced
6718:06d750efbc50 6719:77eb1a41fc06
31 try: 31 try:
32 shutil.rmtree(self.home) 32 shutil.rmtree(self.home)
33 except FileNotFoundError: 33 except FileNotFoundError:
34 pass 34 pass
35 35
36 def testDemoClassic(self): 36 def run_install_demo(self, template, db="anydbm"):
37 with captured_output() as (out, err): 37 with captured_output() as (out, err):
38 install_demo(self.home, 'anydbm', 'classic') 38 install_demo(self.home, db, template)
39 output = out.getvalue().strip() 39 output = out.getvalue().strip()
40 print(output) 40 print(output)
41
42 # verify that db was set properly by reading config
43 with open(self.home + "/config.ini", "r") as f:
44 config_lines = f.readlines()
45
46 self.assertIn("backend = %s\n"%db, config_lines)
41 47
42 # dummy up the return of get_server so the serve_forever method 48 # dummy up the return of get_server so the serve_forever method
43 # raises keyboard interrupt exiting the server so the test exits. 49 # raises keyboard interrupt exiting the server so the test exits.
44 gs = roundup.scripts.roundup_server.ServerConfig.get_server 50 gs = roundup.scripts.roundup_server.ServerConfig.get_server
45 def raise_KeyboardInterrupt(): 51 def raise_KeyboardInterrupt():
59 print(output) 65 print(output)
60 # if the server installed and started this will be the 66 # if the server installed and started this will be the
61 # last line in the output. 67 # last line in the output.
62 self.assertIn("Keyboard Interrupt: exiting", output.split('\n')) 68 self.assertIn("Keyboard Interrupt: exiting", output.split('\n'))
63 69
70 def testDemoClassic(self):
71 self.run_install_demo("classic")
72
64 def testDemoMinimal(self): 73 def testDemoMinimal(self):
65 with captured_output() as (out, err): 74 self.run_install_demo('../templates/minimal', db="sqlite")
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'))
98 75
99 def testDemoJinja(self): 76 def testDemoJinja(self):
100 with captured_output() as (out, err): 77 self.run_install_demo('jinja2', db="anydbm")
101 install_demo(self.home, 'anydbm', 'jinja2')
102 output = out.getvalue().strip()
103 print(output)
104 78
105 # verify that template was set to jinja2 by reading config 79 # verify that template was set to jinja2 by reading config
106 with open(self.home + "/config.ini", "r") as f: 80 with open(self.home + "/config.ini", "r") as f:
107 config_lines = f.readlines() 81 config_lines = f.readlines()
108 82
109 self.assertIn("template_engine = jinja2\n", config_lines) 83 self.assertIn("template_engine = jinja2\n", config_lines)
110 84
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'))

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