Mercurial > p > roundup > code
changeset 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 | 69e6bcb39f90 |
| children | 29ef4b69f18c |
| files | test/test_demo.py |
| diffstat | 1 files changed, 52 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_demo.py Mon Nov 20 19:16:59 2023 -0500 +++ b/test/test_demo.py Mon Nov 20 21:59:40 2023 -0500 @@ -84,14 +84,63 @@ self.assertIn("Keyboard Interrupt: exiting", output.split('\n')) def testDemoClassic(self): - self.run_install_demo("classic") + with captured_output() as (out, err): + self.run_install_demo("classic") + self.assertIn("http://localhost:8917/demo/", out.getvalue()) + + # verify the default anydbm db is created + db_file = self.home + "/db/nodes.user" + self.assertTrue(os.path.isfile(db_file), + "expected db file %s does not exist" % db_file) + + # verify requested template was used + with open(self.home + "/TEMPLATE-INFO.txt", "r") as f: + info_lines = f.read() + + try: + # handle text files with \r\n line endings + info_lines.index("\r", 0, 100) + info_lines = info_lines.replace("\r\n", "\n") + except ValueError: + pass + + self.assertIn("Name: classic-_test_demo\n", info_lines) def testDemoMinimal(self): - self.run_install_demo('../templates/minimal', db="sqlite") + # test explicit path to template as others test template + # search path. + with captured_output() as (out, err): + self.run_install_demo('../templates/minimal', db="sqlite") + self.assertIn("http://localhost:8917/demo/", out.getvalue()) + + # verify the requested sqlite db file is created + db_file = self.home + "/db/db" + self.assertTrue(os.path.isfile(db_file), + "expected db file %s does not exist" % db_file) + + # verify requested template was used + with open(self.home + "/TEMPLATE-INFO.txt", "r") as f: + info_lines = f.read() + + try: + # handle text files with \r\n line endings + info_lines.index("\r", 0, 100) + info_lines = info_lines.replace("\r\n", "\n") + except ValueError: + pass + + self.assertIn("Name: minimal-_test_demo\n", info_lines) @skip_jinja2 def testDemoJinja(self): - self.run_install_demo('jinja2', db="anydbm") + with captured_output() as (out, err): + self.run_install_demo('jinja2', db="anydbm") + self.assertIn("http://localhost:8917/demo/", out.getvalue()) + + # verify the requested anydbm db file is created + db_file = self.home + "/db/nodes.user" + self.assertTrue(os.path.isfile(db_file), + "expected db file %s does not exist" % db_file) # verify that template was set to jinja2 by reading config with open(self.home + "/config.ini", "r") as f:
