Skip to content

Commit

Permalink
Update tests with relative path support
Browse files Browse the repository at this point in the history
Signed-off-by: Paulo Vital <[email protected]>
  • Loading branch information
Paulo Vital authored and alinefm committed Oct 10, 2016
1 parent 5ffb7fe commit d62440c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def setUp(self):
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):
Expand Down
71 changes: 71 additions & 0 deletions tests/test_server_root.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)

Expand Down

0 comments on commit d62440c

Please sign in to comment.