You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_wsgi.py 1.0 KiB

123456789101112131415161718192021222324252627282930313233343536
  1. from nose.tools import *
  2. from nose.tools import assert_raises
  3. from testutil.helpers import *
  4. import io
  5. import os
  6. import sys
  7. import time
  8. import nilmdb.server
  9. import webtest
  10. testdb = "tests/testdb"
  11. # Test WSGI interface
  12. class TestWSGI(object):
  13. def test_wsgi(self):
  14. # Bad database gives debug info
  15. app = webtest.TestApp(nilmdb.server.wsgi_application("/dev/null", "/"))
  16. resp = app.get('/', expect_errors=True)
  17. eq_(resp.status_int, 500)
  18. eq_(resp.content_type, "text/plain")
  19. body = resp.body.decode('utf-8')
  20. in_("Initializing database at path '/dev/null' failed", body)
  21. in_("Not a directory: b'/dev/null/data'", body)
  22. in_("Running as: uid=", body)
  23. in_("Environment:", body)
  24. # Good database works fine
  25. app = webtest.TestApp(nilmdb.server.wsgi_application(testdb, "/nilmdb"))
  26. resp = app.get('/version', expect_errors=True)
  27. eq_(resp.status_int, 404)
  28. resp = app.get('/nilmdb/version')
  29. eq_(resp.json, nilmdb.__version__)