Skip to content

Commit

Permalink
test: actually test output from running demo server code
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rouilj committed Nov 21, 2023
1 parent 5cd5a93 commit 33c9b61
Showing 1 changed file with 52 additions and 3 deletions.
55 changes: 52 additions & 3 deletions test/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,63 @@ def test_get_server(self):
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:
Expand Down

0 comments on commit 33c9b61

Please sign in to comment.