Mercurial > p > roundup > code
comparison test/test_demo.py @ 6545:5a3a386aa8e7
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.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 09 Dec 2021 15:26:39 -0500 |
| parents | 3e33b22a3158 |
| children | 77eb1a41fc06 |
comparison
equal
deleted
inserted
replaced
| 6544:9aa8df0b4426 | 6545:5a3a386aa8e7 |
|---|---|
| 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 testDemo(self): | 36 def testDemoClassic(self): |
| 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, 'anydbm', 'classic') |
| 39 output = out.getvalue().strip() | 39 output = out.getvalue().strip() |
| 40 print(output) | 40 print(output) |
| 41 | 41 |
| 59 print(output) | 59 print(output) |
| 60 # if the server installed and started this will be the | 60 # if the server installed and started this will be the |
| 61 # last line in the output. | 61 # last line in the output. |
| 62 self.assertIn("Keyboard Interrupt: exiting", output.split('\n')) | 62 self.assertIn("Keyboard Interrupt: exiting", output.split('\n')) |
| 63 | 63 |
| 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) | |
| 64 | 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 | |
| 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')) |
