From: Paulo Vital <pvital(a)linux.vnet.ibm.com>
Signed-off-by: Paulo Vital <pvital(a)linux.vnet.ibm.com>
---
tests/test_api.py | 3 +-
tests/test_server_root.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++
tests/utils.py | 4 +--
3 files changed, 75 insertions(+), 3 deletions(-)
create mode 100644 tests/test_server_root.py
diff --git a/tests/test_api.py b/tests/test_api.py
index 0ddf627..c93aff0 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -55,7 +55,8 @@ class APITests(unittest.TestCase):
def test_config(self):
resp = self.request('/config').read()
conf = json.loads(resp)
- keys = ["auth", "ssl_port", "websockets_port",
"version"]
+ keys = ["auth", "ssl_port", "websockets_port",
"version",
+ "server_root"]
self.assertEquals(sorted(keys), sorted(conf.keys()))
def test_user_log(self):
diff --git a/tests/test_server_root.py b/tests/test_server_root.py
new file mode 100644
index 0000000..fb5cf6c
--- /dev/null
+++ b/tests/test_server_root.py
@@ -0,0 +1,71 @@
+#
+# Project Wok
+#
+# Copyright IBM Corp, 2016
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+import json
+import unittest
+
+from utils import get_free_port, patch_auth, request, run_server
+
+
+test_server = None
+model = None
+host = None
+port = None
+ssl_port = None
+
+
+def setup_server(environment='development', server_root=''):
+ global test_server, model, host, port, ssl_port
+
+ patch_auth()
+ host = '127.0.0.1'
+ port = get_free_port('http')
+ ssl_port = get_free_port('https')
+ test_server = run_server(host, port, ssl_port, test_mode=True,
+ environment=environment,
+ server_root=server_root)
+
+
+class ServerRootTests(unittest.TestCase):
+ def tearDown(self):
+ test_server.stop()
+
+ def test_production_env(self):
+ """
+ Test reasons sanitized in production env
+ """
+ server_root = '/test'
+ setup_server('production', server_root)
+
+ # check if server_root in config is the same used to start server
+ resp = request(host, ssl_port, server_root + '/config').read()
+ conf = json.loads(resp)
+ self.assertEquals(len(conf), 5)
+
+ def test_development_env(self):
+ """
+ Test traceback thrown in development env
+ """
+ server_root = '/test'
+ setup_server(server_root=server_root)
+
+ # check if server_root in config is the same used to start server
+ resp = request(host, ssl_port, server_root + '/config').read()
+ conf = json.loads(resp)
+ self.assertEquals(len(conf), 5)
diff --git a/tests/utils.py b/tests/utils.py
index 0fa8a53..d518f13 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -105,7 +105,7 @@ def get_free_port(name='http'):
def run_server(host, port, ssl_port, test_mode, cherrypy_port=None,
- model=None, environment='development'):
+ model=None, environment='development', server_root=''):
if cherrypy_port is None:
cherrypy_port = get_free_port('cherrypy_port')
@@ -120,7 +120,7 @@ def run_server(host, port, ssl_port, test_mode, cherrypy_port=None,
'max_body_size': '4*1024', 'test': test_mode,
'access_log': '/dev/null', 'error_log':
'/dev/null',
'environment': environment, 'log_level':
'debug',
- 'session_timeout': 10})()
+ 'session_timeout': 10, 'server_root': server_root})()
if model is not None:
setattr(args, 'model', model)
--
2.7.4