Mercurial > p > roundup > code
annotate test/test_demo.py @ 7340:7b9bddda9d2d
Add support for demo mode in docker.
roundup/demo.py
Make changes to allow exposed port in docker to be specified
separately from the port that demo mode binds to. Also permit
bind address specification as well.
roundup/scripts/roundup_demo.py:
Update required by changes in demo.py. Also move away from
positional arguments to prefer flag arguments. Required for
passing port and host specification. Flake8 fixes.
share/man/man1/roundup-demo.1
Document use of option flags rather than positional
params. Other cleanups.
doc/installation.txt:
Document new docker modes: demo, shell and admin.
Update docs:
overview section - reorg, added template info
for the impatient section - added docker demo mode reference,
more docs on top level demo.py use.
new section on docker demo mode
removed getting roundup section. folded into installing roundup.
also prior for the impatient section describes how to download.
install via pip in venv recommended supported method
document all provided templates. not just minimal and classic.
added index references.
move sections around, decreased sectin depth, reformatting
scripts/Docker/roundup_healthcheck:
When running roundup-demo, there is no tracker spec. So default to
demo if no tracker=directory args found. Prevent's docker from
reporting an unhealthy container when running demo.
scripts/Docker/roundup_start:
implement demo, shell, admin docker modes.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 14 May 2023 09:43:53 -0400 |
| parents | 77eb1a41fc06 |
| children | 4cfaddc2d53e |
| rev | line source |
|---|---|
|
6324
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
1 import unittest |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
2 import os, sys, shutil |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
3 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
4 from roundup.demo import install_demo, run_demo |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
5 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
6 import roundup.scripts.roundup_server |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
7 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
8 # https://stackoverflow.com/questions/4219717/how-to-assert-output-with-nosetest-unittest-in-python |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
9 # lightly modified |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
10 from contextlib import contextmanager |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
11 _py3 = sys.version_info[0] > 2 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
12 if _py3: |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
13 from io import StringIO # py3 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
14 else: |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
15 from StringIO import StringIO # py2 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
16 @contextmanager |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
17 def captured_output(): |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
18 new_out, new_err = StringIO(), StringIO() |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
19 old_out, old_err = sys.stdout, sys.stderr |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
20 try: |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
21 sys.stdout, sys.stderr = new_out, new_err |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
22 yield sys.stdout, sys.stderr |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
23 finally: |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
24 sys.stdout, sys.stderr = old_out, old_err |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
25 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
26 class TestDemo(unittest.TestCase): |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
27 def setUp(self): |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
28 self.home = os.path.abspath('_test_demo') |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
29 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
30 def tearDown(self): |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
31 try: |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
32 shutil.rmtree(self.home) |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
33 except FileNotFoundError: |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
34 pass |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
35 |
|
6719
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
36 def run_install_demo(self, template, db="anydbm"): |
|
6324
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
37 with captured_output() as (out, err): |
|
6719
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
38 install_demo(self.home, db, template) |
|
6324
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
39 output = out.getvalue().strip() |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
40 print(output) |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
41 |
|
6719
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
42 # verify that db was set properly by reading config |
|
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
43 with open(self.home + "/config.ini", "r") as f: |
|
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
44 config_lines = f.readlines() |
|
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
45 |
|
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
46 self.assertIn("backend = %s\n"%db, config_lines) |
|
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
47 |
|
6324
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
48 # dummy up the return of get_server so the serve_forever method |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
49 # raises keyboard interrupt exiting the server so the test exits. |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
50 gs = roundup.scripts.roundup_server.ServerConfig.get_server |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
51 def raise_KeyboardInterrupt(): |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
52 raise KeyboardInterrupt |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
53 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
54 def test_get_server(self): |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
55 httpd = gs(self) |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
56 httpd.serve_forever = raise_KeyboardInterrupt |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
57 return httpd |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
58 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
59 roundup.scripts.roundup_server.ServerConfig.get_server = test_get_server |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
60 |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
61 # Run under context manager to capture output of startup text. |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
62 with captured_output() as (out, err): |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
63 run_demo(self.home) |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
64 output = out.getvalue().strip() |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
65 print(output) |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
66 # if the server installed and started this will be the |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
67 # last line in the output. |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
68 self.assertIn("Keyboard Interrupt: exiting", output.split('\n')) |
|
3e33b22a3158
BAsic test of demo and server intialization.
John Rouillard <rouilj@ieee.org>
parents:
diff
changeset
|
69 |
|
6719
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
70 def testDemoClassic(self): |
|
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
71 self.run_install_demo("classic") |
|
6545
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
72 |
|
6719
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
73 def testDemoMinimal(self): |
|
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
74 self.run_install_demo('../templates/minimal', db="sqlite") |
|
6545
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
75 |
|
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
76 def testDemoJinja(self): |
|
6719
77eb1a41fc06
test cleanup. Make test method and convert tests to use.
John Rouillard <rouilj@ieee.org>
parents:
6545
diff
changeset
|
77 self.run_install_demo('jinja2', db="anydbm") |
|
6545
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
78 |
|
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
79 # verify that template was set to jinja2 by reading config |
|
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
80 with open(self.home + "/config.ini", "r") as f: |
|
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
81 config_lines = f.readlines() |
|
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
82 |
|
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
83 self.assertIn("template_engine = jinja2\n", config_lines) |
|
5a3a386aa8e7
issue2551179 Load config_ini.ini ... recognize minimal template demo.py
John Rouillard <rouilj@ieee.org>
parents:
6324
diff
changeset
|
84 |
