[Kimchi-devel] [PATCH] [Wok 4/4] Update tests with relative path support

pvital at linux.vnet.ibm.com pvital at linux.vnet.ibm.com
Thu Oct 6 19:09:41 UTC 2016


From: Paulo Vital <pvital at linux.vnet.ibm.com>

Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
 tests/test_api.py           |  3 +-
 tests/test_relative_path.py | 71 +++++++++++++++++++++++++++++++++++++++++++++
 tests/utils.py              |  4 +--
 3 files changed, 75 insertions(+), 3 deletions(-)
 create mode 100644 tests/test_relative_path.py

diff --git a/tests/test_api.py b/tests/test_api.py
index 0ddf627..6aff867 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",
+                "relative_path"]
         self.assertEquals(sorted(keys), sorted(conf.keys()))
 
     def test_user_log(self):
diff --git a/tests/test_relative_path.py b/tests/test_relative_path.py
new file mode 100644
index 0000000..f0d7400
--- /dev/null
+++ b/tests/test_relative_path.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', relative_path=''):
+    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,
+                             relative_path=relative_path)
+
+
+class RelativePathsTests(unittest.TestCase):
+    def tearDown(self):
+        test_server.stop()
+
+    def test_production_env(self):
+        """
+        Test reasons sanitized in production env
+        """
+        relative_path = '/test'
+        setup_server('production', relative_path)
+
+        # check if relative_path in config is the same used to start server
+        resp = request(host, ssl_port, relative_path + '/config').read()
+        conf = json.loads(resp)
+        self.assertEquals(len(conf), 5)
+
+    def test_development_env(self):
+        """
+        Test traceback thrown in development env
+        """
+        relative_path = '/test'
+        setup_server(relative_path=relative_path)
+
+        # check if relative_path in config is the same used to start server
+        resp = request(host, ssl_port, relative_path + '/config').read()
+        conf = json.loads(resp)
+        self.assertEquals(len(conf), 5)
diff --git a/tests/utils.py b/tests/utils.py
index 0fa8a53..d5c3f84 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', relative_path=''):
 
     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, 'relative_path': relative_path})()
     if model is not None:
         setattr(args, 'model', model)
 
-- 
2.7.4




More information about the Kimchi-devel mailing list